'StructureMap.ObjectFactory' 已过时

'StructureMap.ObjectFactory' is obsolete

我使用 StructureMap 实现了接口注入,如下所述。

ObjectFactory.Initialize(x => { x.For<*IRepository*>().Use<*SQLRepository*>(); });

但是提示如下

Warning 2 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work'.

如何使用 Container class

更正此问题

您可以根据他们的 documentation 直接创建容器实例。语法比较相似。

var container = new Container(x =>
{
    x.ForRequestedType<IRepository>().Use<SQLRepository>();
});