我在我的应用程序中使用StructureMap和ASP.Net Identity。当我在我的Application_Start
StructureMap认为它必须注入构造函数并抛出异常
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的问题,而不是我的代码。
感谢您的原因。但StructureMap支持多个构造函数。我添加了这个到我的配置和工作:)'x.ForConcreteType()。Configure.SelectConstructor(()=>新的AccountController());'所以请更新您的答案,所以我检查它被接受。 –
2015-03-24 23:08:08
@ahmadalishafiee:查看我的关于构造函数的编辑。还编辑我的答案作为您的解决方案的反应 – 2015-03-25 10:53:47