2014-01-10 19 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中的一切,问题已经不再是问题