我在我的应用程序中使用 StructureMap 和 ASP.Net Identity。当我有这条线时Application_Start
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
这是StructureMapControllerFactory
:
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null && requestContext.HttpContext.Request.Url != null)
throw new InvalidOperationException(string.Format("Page not found: {0}",
requestContext.HttpContext.Request.Url.AbsoluteUri.ToString(CultureInfo.InvariantCulture)));
return ObjectFactory.GetInstance(controllerType) as Controller;
}
}
return ObjectFactory.GetInstance(controllerType) as Controller;
抛出StructureMapConfigurationException
异常说:
No default Instance is registered and cannot be automatically determined for type 'IUserStore<Person>'
但是如果我删除ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
行一切都很好,所以这是 StructureMap 的问题,而不是我的代码。