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工作正常。