Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以将上下文绑定与StructureMap一起使用_C#_Dependency Injection_Structuremap - Fatal编程技术网

C# 是否可以将上下文绑定与StructureMap一起使用

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

我有一个MVC4控制器,如:

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();