2012-06-20 90 views
2

看起來您在StructureMap中每個插件類型只能有一個生命週期策略。有沒有辦法解決?這個簡單的控制檯應用程序表明,無論生命週期是「最後」,「勝利」。StructureMap - 每個命名實例的不同生命週期

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"); 
    } 
    } 
} 

回答

0

這已在StructureMap 3.0中修復。現在您可以簡單地更改每個實例的生命週期。