StructureMapでは、プラグインタイプごとに1つのライフサイクルポリシーしか持てないようです。これを回避する方法はありますか?このシンプルなコンソールアプリは、ライフサイクルが「最後」「勝つ」ことを示しています。
namespace StructureMapLifecycle
{
public class Program
{
public static void Main(string[] args)
{
StructureMap.ObjectFactory.Initialize(
x =>
{
x.For<ISomething>().Add<SomethingA>().Named("A");
x.For<ISomething>().Singleton().Add<SomethingB>().Named("B");
x.For<ISomething>().Add<SomethingC>().Named("C");
x.For<ISomething>().HybridHttpOrThreadLocalScoped().Use<SomethingC>();
});
Console.Write(StructureMap.ObjectFactory.WhatDoIHave());
Console.ReadLine();
}
}
public interface ISomething
{
void DoSomething();
}
public class SomethingA : ISomething
{
public void DoSomething()
{
Console.WriteLine("Do something A");
}
}
public class SomethingB : ISomething
{
public void DoSomething()
{
Console.WriteLine("Do something B");
}
}
public class SomethingC : ISomething
{
public void DoSomething()
{
Console.WriteLine("Do something C");
}
}
}