我在 MVC5 中使用结构图 3.1.2.138。在我的 IoC 类中,我正在尝试使用 Objectfactory,但它指出 Objectfactory 已过时,我应该使用 Container,但我找不到使这项工作的方法。
public static IContainer Initialize() {
var BS_WebDataContextConnectionString = "Data Source=xxx;Initial Catalog=xxx;Integrated Security=True;MultipleActiveResultSets=True";
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.Assembly(Assembly.GetCallingAssembly());
scan.WithDefaultConventions();
});
//DataContext
x.For<iBS_WebDataContext>().Use<BS_WebDataContext>()
.Ctor<string>("connectionString")
.Is(BS_WebDataContextConnectionString);
//Repositories
x.For<IReadOnlyEvidenceTypeRepository>().Use<EF6ReadOnlyEvidenceTypeRepository>();
x.For<IReadOnlyStatusCategoryRepository>().Use<EF6ReadOnlyStatusCategoryRepository>();
//Services
x.For<IEvidenceTypeService>().Use<EvidenceTypeService>();
x.For<IStatusCategoryService>().Use<StatusCategoryService>();
});
return ObjectFactory.Container;
}
谁能给我一个如何将其转换为容器方式的示例?