Why is the IDependecyResolver trying to get an instance of IControllerFactory although I registered the 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);
}
}
Thrown error:
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.Web.Mvc.IControllerFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
In MVC3, the DependencyResolver (which is a service locator) is used to attempt to locate an applicable type. If it cannot find a type, then it resumes looking through using the legacy code, which is the ControllerBuilder.Current
instance. The important thing here is that it checks via the DependencyResolver, your StructureMap container. MVC3 requires that the DependencyResolver returns null
for when it cannot find a type, it won't be the framework's responsibility to catch any exceptions from your container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With