我想要如何配置ASP.NET MVC3的StructureMap我已经使用NuGet,我注意到它创建了一个名为StructuremapMVC的cs文件的App_Start文件夹,所以我检查它并注意是相同的代码,但简化,将手动写上放置在Global.asax中App_Start节...首先尝试通过NuGet的StructureMap和MVC3
这是国际奥委会类我的代码
public static class IoC
{
public static IContainer Initialize()
{
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.AddAllTypesOf<IController>();
});
x.For<OpcionDB>().Use(() => new DatabaseFactory().Get());
});
return ObjectFactory.Container;
}
}
我的问题是,为什么我得到当我在我的控制器上注入一些IoC时(下面我使用这种模式:Entity Framework 4 CTP 4/CTP 5 Generic Repository Pattern and Unit Testable):
private readonly IAsambleaRepository _aRep;
private readonly IUnitOfWork _uOw;
public AsambleaController(IAsambleaRepository aRep, IUnitOfWork uOw)
{
_aRep = aRep;
this._uOw = uOw;
}
public ActionResult List(string period)
{
var rs = _aRep.ByPeriodo(period).ToList<Asamblea>();
return View();
}
异常表明:
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
+1:这对我有帮助。谢谢。 – 2012-07-31 14:20:53
在我使用StructureMap的所有年份中,我从来没有注意到这一点,我想我会把这个尝试块取消。我认为我不希望StructureMap不会冒泡。 – 2012-07-31 15:35:33