gpt4 book ai didi

.net - StructureMap:如何为其所有接口(interface)注册相同的实例

转载 作者:行者123 更新时间:2023-12-04 10:12:51 25 4
gpt4 key购买 nike

StructureMap 新手问题。

public class SomeClass: IInterface1, IInterface2 {
}

我希望通过以下测试:
Assert.AreSameInstance(
container.GetInstance<IInterface1>(),
container.GetInstance<IInterface2>());

我将如何对此进行显式注册?

我知道在温莎城堡我会做类似的事情
kernel.Register(Component.For(typeof(IInterface1), typeof(IInterface2))
.ImplementedBy(typeof(SomeClass));

但我没有看到任何等效的 API

最佳答案

ObjectFactory.Initialize(x => 
{
x.For<IInterface1>().Singleton().Use<MyClass>();
x.Forward<IInterface1, IInterface2>();
});

关于.net - StructureMap:如何为其所有接口(interface)注册相同的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2535178/

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