回答

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(); 
} 
相关问题