<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Using the Web API Dependency Resolver</title><link>http://www.asp.net</link><pubDate>Tue, 14 May 2013 08:30:53 GMT</pubDate><generator>umbraco</generator><description>Comments for Using the Web API Dependency Resolver</description><language>en</language><atom:link href="http://www.asp.net/rss/comments/37004" rel="self" type="application/rss+xml" /><item><title>Comment Posted by crixo</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Mon, 20 Feb 2012 03:00:07 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014883</guid><description><![CDATA[ <p>what about an hook to Release components??</p><p>Since web api is now part of mvc, I assume you can use </p><p>&quot;System.Web.Mvc.ControllerBuilder.Current.SetControllerFactory &quot;</p><p>for api controller as well.</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/crixo.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by mike.j.pappas</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Tue, 28 Feb 2012 16:42:11 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014965</guid><description><![CDATA[ <p>I am trying to use MEF to inject dependencies but for some reason I keep getting the following error:  </p><p>An error occurred when trying to create a controller of type &#39;...AccountsController&#39;. Make sure that the controller has a parameterless public constructor.</p><p></p><p>I used the last example you provided for Unity above, changing the lines to:</p><p>                    string name = AttributedModelServices.GetContractName(t);</p><p>                    return container.GetExportedValueOrDefault&lt;object&gt;(name);</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/mike.j.pappas.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by mike.j.pappas</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Tue, 28 Feb 2012 16:42:45 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000014966</guid><description><![CDATA[ <p>Is there an example that uses MEF to inject dependencies?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/mike.j.pappas.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by evan.larsen</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Wed, 07 Mar 2012 12:46:33 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015051</guid><description><![CDATA[ <p>Mike Wasson, I followed your tutorial and used a Unity Container.  I followed this article to the T and it seems my api controller is getting instantiated (i can see this while stepping thru).  But my problem is immediately after my apicontroller is instantiated.  Please see my post on the forums here:</p><p><a rel="nofollow" href="http://forums.asp.net/t/1777791.aspx/1?Web" target="_blank">forums.asp.net/</a>+Api+Dependency+Resolver+works+but+Action+Invoker+isn+t+</p><p></p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/evan.larsen.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by nikos baxevanis</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Sun, 18 Mar 2012 11:03:36 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015144</guid><description><![CDATA[ <p>Using the Web API Dependency Resolver with Castle Windsor can be found here <a rel="nofollow" href="http://www.nikosbaxevanis.com/bonus-bits/2012/03/using-the-web-api-dependency-resolver-with-castle-windsor.html" target="_blank">www.nikosbaxevanis.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/nikos%20baxevanis.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by malkov</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Fri, 06 Apr 2012 08:11:46 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015265</guid><description><![CDATA[ <p>Good post about how to use Unity with ASP.NET MVC 4 and WebAPI:</p><p><a rel="nofollow" href="http://netmvc.blogspot.com/2012/04/dependency-injection-in-aspnet-mvc-4.html" target="_blank">netmvc.blogspot.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/malkov.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by malovicn</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Thu, 31 May 2012 18:29:05 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015640</guid><description><![CDATA[ <p>The approach here requires explicit regiostration of controllers which is nto needed with Unity. If you change the GetService implementation in this then no need to register any api controller which removes some friction...</p><p></p><p>public object GetService(Type serviceType)</p><p> {</p><p>        if (!Container.IsRegistered(serviceType))</p><p>            {</p><p>                if (serviceType.IsAbstract || serviceType.IsInterface)</p><p>                {</p><p>                    return null;</p><p>                }</p><p>            }</p><p>            return Container.Resolve(serviceType);</p><p>        }</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/malovicn.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by silverstar123</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Mon, 04 Jun 2012 02:07:12 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015667</guid><description><![CDATA[ <p>This doesn&#39;t work in RC. throws system.web.http.services.Idependencyresolver cannot be created error</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/silverstar123.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by panesofglass</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Wed, 06 Jun 2012 10:04:14 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015694</guid><description><![CDATA[ <p>The link to <a rel="nofollow" href="http://www.asp.net/web-api/overview/extensibility/crud.html" target="_blank">www.asp.net/</a> returns a 404, and it might be worth noting that retrieving instances should go through config.Services, not config.DependencyResolver.</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/panesofglass.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by panesofglass</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Wed, 06 Jun 2012 12:28:02 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015696</guid><description><![CDATA[ <p>For those confused as to when you might use Services versus DependencyResolver, see the following work item on CodePlex: <a rel="nofollow" href="http://aspnetwebstack.codeplex.com/workitem/26" target="_blank">aspnetwebstack.codeplex.com/</a></p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/panesofglass.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by camitz</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Mon, 18 Jun 2012 03:53:44 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015795</guid><description><![CDATA[ <p>GetService gives my </p><p></p><p>Unable to cast object of type &#39;Microsoft.Practices.ObjectBuilder2.TransientLifetimePolicy&#39; to type &#39;Microsoft.Practices.Unity.LifetimeManager&#39;.</p><p></p><p>alot of the time. What am I doing wrong?</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/camitz.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by patel_sir8</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Sun, 01 Jul 2012 01:47:40 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000015889</guid><description><![CDATA[ <p>good one..</p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/patel_sir8.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by drumboog</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Mon, 30 Jul 2012 16:55:48 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016069</guid><description><![CDATA[ <p>This looks really good... should be very helpful.</p><p>Is there a reason that IDependencyResolver implements IDependencyScope?  When do GetService/GetServices get called directly from IDependencyResolver without going through BeginScope first?</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/drumboog.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by zerg</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Tue, 21 Aug 2012 11:24:40 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016235</guid><description><![CDATA[ <p>Hi, Mike :) I try to implement all like in a post and it works grate. But sometimes I can see error: &quot;An error occurred when trying to create a controller of type &#39;...AccountsController&#39;. Make sure that the controller has a parameterless public constructor.&quot;</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/zerg.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by kate0824</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Thu, 25 Oct 2012 04:01:29 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000016674</guid><description><![CDATA[ <p>it seems that the way doesn&#39;t support Generic object. When I register a generic service, I get an error. Any way to resolve this problem?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/kate0824.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by cuiqs</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Sun, 16 Dec 2012 09:15:17 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000017017</guid><description><![CDATA[ <p>Is there an example that uses MEF to inject dependencies?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/cuiqs.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Sid D</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Mon, 28 Jan 2013 15:51:40 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000018268</guid><description><![CDATA[ <p>One way I found of extending this behavior to standard MVC controllers is to set the MVC.DependencyResolver to this config.DependencyResolver.  I did this by putting the following at the end of the ConfigureAPI method: </p><p>DependencyResolver.SetResolver(config.DependencyResolver);  </p><p>I then made the IOCContainer class implement the IServiceLocator, passing the calls from the IDependencyScope &quot;GetService&quot; of the to the &quot;GetInstance&quot; methods of the IServiceLocator.  Feasible for WebAPI+MVC projects?</p>]]></description><enclosure length="0" type="image/png" url="http://i3.asp.net/avatar/Sid%20D.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by rosieks</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Thu, 04 Apr 2013 03:51:13 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000018850</guid><description><![CDATA[ <p>Hi, I have question about container.IsRegistered. That method is intended to debug only, is slow and additionaly sometimes cause InvalidOperationException because of registration collection has been changed.</p><p></p><p>System.InvalidOperationException: Collection was modified; enumeration operation may not execute.</p><p></p><p>How to manage with that case?</p>]]></description><enclosure length="0" type="image/png" url="http://i2.asp.net/avatar/rosieks.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item><item><title>Comment Posted by Maqsood7</title><link>http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver</link><pubDate>Tue, 14 May 2013 08:30:53 GMT</pubDate><guid isPermaLink="false">00000000-0000-0000-0000000019104</guid><description><![CDATA[ <p>Can&#39;t we use factory pattern where the factory gives me required object for IProductRepository?</p><p></p><p>Something like </p><p>public class ProductsController : ApiController</p><p>{</p><p>    private readonly IProductRepository repository;</p><p>    public ProductsController()</p><p>    {</p><p>        if (repository == null)</p><p>        {</p><p>            this.repository = factory.GetInstance(&quot;ProductsController&quot;);</p><p>        }</p><p>    }</p><p> ......</p><p></p>]]></description><enclosure length="0" type="image/png" url="http://i1.asp.net/avatar/Maqsood7.jpg?forceidenticon=false&amp;dt=635045689200000000&amp;enableAvatar=False&amp;cdn_id=2013-05-10-001" /></item></channel></rss>