tag:blogger.com,1999:blog-4394562672296169849.post4656585892250785184..comments2023-12-21T18:06:15.136+08:00Comments on class Programmer : IEnableMuch {: Minimalistic ArchitectureIEnableMuchhttp://www.blogger.com/profile/01393635235961303977noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-4394562672296169849.post-90248967063623834972015-10-11T22:06:17.753+08:002015-10-11T22:06:17.753+08:00great post and its realy informative , thanks so m...great post and its realy informative , thanks so muchluihttp://www.mytrickspedia.blogspot.comnoreply@blogger.comtag:blogger.com,1999:blog-4394562672296169849.post-17017842703736937132014-11-05T21:54:14.433+08:002014-11-05T21:54:14.433+08:00I haven't yet tried SimpleInjector, I might ch...I haven't yet tried SimpleInjector, I might check it out<br /><br />DryIoc is the fastest, see benchmark: http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison<br /><br />There is just no way to dispose objects with DryIoc yet, or I haven't find it out yet. An example use:<br /><br />protected override System.Web.Mvc.IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)<br />{<br />System.Web.Mvc.IController ic = controllerType == null<br />? null<br />: (System.Web.Mvc.IController)_container.Resolve(controllerType);<br /><br />return ic; // when the controller gets disposed?<br />}<br /><br /><br />On LightInject, resolving objects are enclosed in a scope, the object's Dispose method gets called when the scope ends. An example:<br /><br />protected override System.Web.Mvc.IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)<br />{<br />using (_container.BeginScope())<br />{<br /><br />System.Web.Mvc.IController ic = controllerType == null<br />? null<br />: (System.Web.Mvc.IController)_container.GetInstance(controllerType);<br /><br />return ic; // this gets disposed when this scope ends<br />}<br />}<br /><br />See the LightInject's Lifetime section here (bookmark is broken): http://www.lightinject.net/#toc8<br /><br />LightInject has interception with a nice performance too, DryIoc has no interception yet. Though HaveBox's interception is the fastest, it seems its container has two kinds of lifetimes only, not flexible<br /><br />In terms of difficulty, I find the young containers are easier to use as their APIs are lambda-oriented. Other than that, they just differ in naming things, e.g., DryIoc's Resolve versus LightInject's GetInstance<br /><br />As for easier to use in ASP.NET Web API, I just followed Mark Seemann's approach: http://blog.ploeh.dk/2012/10/03/DependencyInjectioninASP.NETWebAPIwithCastleWindsor/<br /><br />Here's an implementation of that adapted to DryIoc (before I learned of LightInject): http://www.ienablemuch.com/2014/09/dryioc-aspnet-web-api-error.html<br /><br />For sure, you'll just change less than five lines to adapt the above approach to LightInject, SimpleInjector, any IoC/DI for that matter<br /><br /><br /><br />I think you can't go wrong with LightInject too. Here's one of Daniel Palme's conclusions:<br /><br />"DryIoc, LightInject and SimpleInjector offer a very performance combined with support for advanced scenarios like interception and generic decorators.<br />Simple Injector and LightInject also provide extensive documentation and support all important platforms."IEnableMuchhttps://www.blogger.com/profile/01393635235961303977noreply@blogger.comtag:blogger.com,1999:blog-4394562672296169849.post-67831696971365780372014-11-05T17:50:26.961+08:002014-11-05T17:50:26.961+08:00In one of your previous post I noticed you were tr...In one of your previous post I noticed you were trying DryIoc. It seems now that you prefer LightInject. <br />I've always used StructureMap in my projects and I've always liked it. It is quite slow, though. <br />I was trying to switch to a faster IoC and I decided to test SimpleInjector. I don't seem to be able to figure out which is the easiest (and of course fastest) to integrate in a Web.Api project. <br />SimpleInjector seems a little bit too complicated to understand (compared to StructureMap). <br />Could you share some light? <br /><br />Thanks.LeftyXhttps://www.blogger.com/profile/11354220664668987975noreply@blogger.com