StructureMap:如何为其所有接口注册相同的实例

时间:2010-03-29 00:27:22

标签: .net inversion-of-control structuremap

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

1 个答案:

答案 0 :(得分:15)

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