2014-01-10 52 views
1
使用Configuration Manager

我正在使用MVC4項目結構圖,我嘗試使用配置管理器中的ObjectFactory:Stucture地圖中的ObjectFactory

public static IContainer Initialize() { 
     ObjectFactory.Initialize(x => 
        { 

         x.Scan(scan => 
           { 
            scan.TheCallingAssembly(); 
            scan.WithDefaultConventions(); 
           }); 

         var someConfiguration = ConfigurationManager.GetSection("someconfiguration") as SomeConfigurationSection; 


        }); 
     return ObjectFactory.Container; 
    } 

我有錯:

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: An error occurred creating the configuration section handler for someconfiguration: This method cannot be called during the application's pre-start initialization phase. 

是有可能我無法在Object Factory中使用配置管理器?如果不是,有什麼可能的方式來讀取web.config的依賴注入purpouses?

P.S. 沒有使用ObjcetFactory,ConfigurationManager工作正常。

回答

0

我剛剛發現自己的問題的答案。

結構圖正在打造App_Start和特殊類文件正在初始化廠

[assembly: WebActivator.PreApplicationStartMethod(typeof(Web.UI.App_Start.StructuremapMvc), "Start")] 
namespace Web.UI.App_Start 

如果只是複製/粘貼,這是在Start方法Global.asax中的一切,問題已經不再是問題