StructureMap:如何注册的所有接口相同的实例 [英] StructureMap: How to register the same instance for all its interfaces
本文介绍了StructureMap:如何注册的所有接口相同的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
StructureMap新手的问题。
公共类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()使用<。&MyClass的GT;();
x.Forward&所述; IInterface1,IInterface2>();
});
StructureMap newbie question.
public class SomeClass: IInterface1, IInterface2 {
}
I would like the following test to pass:
Assert.AreSameInstance(
container.GetInstance<IInterface1>(),
container.GetInstance<IInterface2>());
How would I do an explicit registration of this?
I know in Castle Windsor I would do something like
kernel.Register(Component.For(typeof(IInterface1), typeof(IInterface2))
.ImplementedBy(typeof(SomeClass));
But I don't see any equivalent API
解决方案
ObjectFactory.Initialize(x =>
{
x.For<IInterface1>().Singleton().Use<MyClass>();
x.Forward<IInterface1, IInterface2>();
});
这篇关于StructureMap:如何注册的所有接口相同的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文