Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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# 4.0 从windsor到structuremap的重构语句_C# 4.0_Castle Windsor_Structuremap - Fatal编程技术网

C# 4.0 从windsor到structuremap的重构语句

C# 4.0 从windsor到structuremap的重构语句,c#-4.0,castle-windsor,structuremap,C# 4.0,Castle Windsor,Structuremap,我有下面的windsor语句,并试图将其转换为structuremap语句。我真的找不到任何建议怎么做 Container.Register(AllTypes.FromThisAssembly(). BasedOn<IType>().If(MatchStatement).Configure(c => c.LifeStyle.Transient. Named(c.Implementation.Name))); Container.Register(AllType

我有下面的windsor语句,并试图将其转换为structuremap语句。我真的找不到任何建议怎么做

Container.Register(AllTypes.FromThisAssembly().
    BasedOn<IType>().If(MatchStatement).Configure(c => c.LifeStyle.Transient.
    Named(c.Implementation.Name)));
Container.Register(AllTypes.FromThisAssembly()。
BasedOn().If(MatchStatement).Configure(c=>c.LifeStyle.Transient)。
命名(c.Implementation.Name));
有人知道structuremap是怎么写的吗

编辑:使其更清晰。。我已经用Windsor Castle写了上面的声明(几乎无论如何),但是因为我们将使用Structuremap,所以我需要用Structuremap做同样的事情。我得到了一部分,但不是全部

        Registry.Scan(x =>
                          {
                              x.TheCallingAssembly();
                              x.AddAllTypesOf<IType>();
                              //{What more?}
                          });
Registry.Scan(x=>
{
x、 装配件();
x、 AddAllTypesOf();
//{还有什么?}
});

我进一步需要的是满足MatchStatement条件并返回命名实例。

StructureMap的默认生命周期是PerGraph(瞬态和单例的混合)

下面的代码扫描调用程序集并添加
IType
的所有实现,每个实现都用实现的名称注册

Scan(scan =>
{
    scan.TheCallingAssembly();
    scan.AddAllTypesOf<IType>().NameBy(type => type.Name);      
});
Scan(扫描=>
{
扫描。卡入总成();
scan.AddAllTypesOf().NameBy(type=>type.Name);
});

您能解释一下您想要实现的目标吗?是否要使用临时生命周期注册并连接具有特定名称的IType的所有实现?是的,这是正确的。它还需要满足条件匹配语句(bool表达式),这是因为我们正在从Windsor迁移到Structuremap。最麻烦的是条件部分。条件做什么?是bool吗?是的,条件返回bool,true/false,所以您只希望在发生什么情况时注册类型?!它是生命周期的条件配置吗?因此,默认情况下,所有实现都是单例的(CastleWindsor),当条件等于true时,生命周期是短暂的?