我想要如何配置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