回答

5

作爲一般規則,你應該總是設置你的IoC容器在Application_Start事件處理程序,因爲它只需要應用程序的生命週期內發生一次

在StructureMap,the documentation recommends的情況下,到container configuration code在一個單獨的Bootstrapper類分開:

public static class Bootstrapper 
{ 
    public static void Bootstrap() 
    { 
     // ObjectFactory.Initialize(... 
    } 
} 

,你再從Application_Start事件處理程序調用:

protected void Application_Start() 
{ 
    Bootstrapper.Bootstrap(); 
} 
相關問題