C# 是否可以将上下文绑定与StructureMap一起使用
我有一个MVC4控制器,如:C# 是否可以将上下文绑定与StructureMap一起使用,c#,dependency-injection,structuremap,C#,Dependency Injection,Structuremap,我有一个MVC4控制器,如: public MyThingyController { IThingy thingy1; IThingy thingy2; public MyClass(IThingy thingy1, IThingy thingy2) { this.thingy1 = thingy1; this.thingy2 = thingy2; } } 我有两个不同的具体实现,我想在这两个实现之间慢慢移动 对于ninject,我会使用 但是我的Googl
public MyThingyController
{
IThingy thingy1;
IThingy thingy2;
public MyClass(IThingy thingy1, IThingy thingy2) {
this.thingy1 = thingy1;
this.thingy2 = thingy2;
}
}
我有两个不同的具体实现,我想在这两个实现之间慢慢移动
对于ninject,我会使用
但是我的GoogleFoo在搜索StructreMap时完全失败了
所以我想设置StructureMap,比如:
public class IocConfig
{
public static IContainer GetCommonServiceLocator()
{
ObjectFactory.Initialize(x =>
{
x.For<IThingy>()
.Use<LegacyThingy>();
x.For<IThingy>()
.Use<ShinyNewThingy>();
});
return ObjectFactory.Container;
}
}
公共类IocConfig
{
公共静态IContainer GetCommonServiceLocator()
{
ObjectFactory.Initialize(x=>
{
x、 For()
.使用();
x、 For()
.使用();
});
返回ObjectFactory.Container;
}
}
这应该可以完成以下工作:
x.For<MyThingyController>()
// or better interface
// x.For<IMyThingyController>()
.Use<MyThingyController>()
.Ctor<IThingy>("thingy1")
.Is<LegacyThingy>()
.Ctor<IThingy>("thingy2")
.Is<ShinyNewThingy>();
x.For()
//或更好的接口
//十,()
.Use()
.Ctor(“thingy1”)
.Is()
.Ctor(“thingy2”)
.Is();