<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Vagif Abilov's blog on .NET : Dependency injection</title><link>http://bloggingabout.net/blogs/vagif/archive/tags/Dependency+injection/default.aspx</link><description>Tags: Dependency injection</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Selecting IoC framework</title><link>http://bloggingabout.net/blogs/vagif/archive/2009/10/27/selecting-ioc-framework.aspx</link><pubDate>Tue, 27 Oct 2009 09:10:04 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:482378</guid><dc:creator>Vagif Abilov</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/vagif/rsscomments.aspx?PostID=482378</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/vagif/commentapi.aspx?PostID=482378</wfw:comment><comments>http://bloggingabout.net/blogs/vagif/archive/2009/10/27/selecting-ioc-framework.aspx#comments</comments><description>&lt;p&gt;No, I haven’t chosen one to use yet. But I kind of feel that instead of investing more time in home-made and fairly inefficient DI classes, I should rewire the code to use one of the available IoC frameworks. And here are some blog posts that can help to make a choice.&lt;/p&gt;  &lt;p&gt;Comparing .NET DI (IoC) Frameworks (&lt;a href="http://blog.ashmind.com/index.php/2008/08/19/comparing-net-di-ioc-frameworks-part-1/" target="_blank"&gt;part1&lt;/a&gt; and &lt;a href="http://blog.ashmind.com/index.php/2008/09/08/comparing-net-di-ioc-frameworks-part-2/" target="_blank"&gt;part2&lt;/a&gt;) by Andrey Shchekin. Very good comparison with source code uploaded to &lt;a href="http://code.google.com/p/net-ioc-frameworks/" target="_blank"&gt;Google Code&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://elegantcode.com/2009/01/07/ioc-libraries-compared/" target="_blank"&gt;IoC libraries compared&lt;/a&gt; by Chirs Brandsma. Focuses on most common case - constructor injection. Source code is &lt;a href="https://cid-b0ed6c076f2f2bfe.skydrive.live.com/self.aspx/Public/IocDemo.zip" target="_blank"&gt;also available&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Having read these two posts, I’d probably go with either StructureMap or Autofac. But I would also like to have a closer look at MEF that was not covered in these blog posts (I guess because it’s not a pure IoC container). &lt;a href="http://ayende.com/Blog/archive/2008/09/25/the-managed-extensibility-framework.aspx" target="_blank"&gt;Here’s&lt;/a&gt; an excellent Ayende’s post explaining why.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=482378" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/vagif/archive/tags/Dependency+injection/default.aspx">Dependency injection</category></item><item><title>Dependencies without injection</title><link>http://bloggingabout.net/blogs/vagif/archive/2009/09/17/dependencies-without-injection.aspx</link><pubDate>Thu, 17 Sep 2009 09:32:53 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:482209</guid><dc:creator>Vagif Abilov</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/vagif/rsscomments.aspx?PostID=482209</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://bloggingabout.net/blogs/vagif/commentapi.aspx?PostID=482209</wfw:comment><comments>http://bloggingabout.net/blogs/vagif/archive/2009/09/17/dependencies-without-injection.aspx#comments</comments><description>&lt;p&gt;Logging is one of the most popular areas used as example to illustrate dependecy injection technique. Components need to log their activities, and to remove hard dependency on actual logger implementation, it’s reasonable to define an interface (something like ILog) that is sent to class constructors, thus freeing components from knowledge about logging details.&lt;/p&gt;  &lt;p&gt;Unfortunately things are different in practice. And if your application uses several third-party libraries that depend on different logging frameworks, you are often out of luck if you try to harmonize their logging and route its output to common log sinks (or listeners).&lt;/p&gt;  &lt;p&gt;Take for example log4net. It’s LogManager looks DI-compliant: it has a method GetLogger that returns an instance of ILog interface:&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;ILog log = LogManager.GetLogger(“MyLog”);&lt;/pre&gt;

&lt;p&gt;You would then expect a way to configure LogManager to return a custom logger. Nope! You can’t control that. log4net does not give you a chance to write your own logger.&lt;/p&gt;

&lt;p&gt;But isn’t this wish outside log4net purpose? Since ILog interface is not a generic .NET interface but a contract that is defined by log4net, isn’t it fair to assume that log4net will use its own logging engine leaving possibilities to write custom appenders? Well, as long as log4net is the only third-party component that you use, this will be sufficient. Once you add more, this can become a problem.&lt;/p&gt;

&lt;p&gt;Our components use Enterprise Library Logging Application Block for its logging purposes. Recently we started using WCF and NHibernate and would like to aggregate all log output. Not an easy task.&lt;/p&gt;

&lt;p&gt;With WCF it seems that there is a way to redirect its logging. There is a special log listener called EntLibLoggingProxyTraceListener used as a bridge between WCF log messages and Enteprise Library LAB. But NHibernate uses log4net, and it looks that the only way to route NHibernate logs to our listeners is to write a special appender. The effort to write such appender is not more complex than to write a custom implementation of ILog interface. I just believe that if a framework provide all necessary elements to fully implement dependency injection pattern (interface definition, factory), it should make the last step and make class instantiation configurable, opening for external implementation of the class.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://bloggingabout.net/aggbug.aspx?PostID=482209" width="1" height="1"&gt;</description><category domain="http://bloggingabout.net/blogs/vagif/archive/tags/logging/default.aspx">logging</category><category domain="http://bloggingabout.net/blogs/vagif/archive/tags/Dependency+injection/default.aspx">Dependency injection</category></item></channel></rss>