gpt4 book ai didi

c# - “StructureMap.ObjectFactory”已过时

转载 作者:太空狗 更新时间:2023-10-30 00:18:45 26 4
gpt4 key购买 nike

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

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 类纠正此问题

最佳答案

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

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

关于c# - “StructureMap.ObjectFactory”已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30723136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com