ASP.NET MVC 3: IDepencyResolver is trying to get an implementation of IControllerFactory

Why is IDependecyResolver trying to get an instance of IControllerFactory even though I registered DefaultControllerFactory ?

Global.asax:

ControllerBuilder.Current.SetControllerFactory(typeof(DefaultControllerFactory)); DependencyResolver.SetResolver(new StructureMapDependencyResolver()); 

Resolver:

 public class StructureMapDependencyResolver : IDependencyResolver { public static Func<Type, object> GetServiceViaDepencencyCallback = t => { throw new NotImplementedException( "StructureMapDependencyResolver is not configured!"); }; public static Func<Type, IEnumerable<object>> GetServicesViaDepencencyCallback = t => { throw new NotImplementedException( "StructureMapDependencyResolver is not configured!"); }; public object GetService(Type serviceType) { return GetServiceViaDepencencyCallback(serviceType); } public IEnumerable<object> GetServices(Type serviceType) { return GetServicesViaDepencencyCallback(serviceType); } } 

Reset Error:

StructureMap exception code: 202 None The default instance defined for PluginFamily System.Web.Mvc.IControllerFactory, System.Web.Mvc, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35

+4
source share
1 answer

In MVC3, DependencyResolver (which is the service locator) is used to find the appropriate type. If it cannot find the type, it resumes browsing using the legacy code, which is an instance of ControllerBuilder.Current . The important thing is that it checks through DependencyResolver, your StructureMap container. MVC3 requires DependencyResolver to return null when it cannot find any type, it will not be the main responsibility to catch any exceptions from your container.

+8
source

Source: https://habr.com/ru/post/1341526/


All Articles