HttpModule和Structuremap初始化

时间:2012-10-22 14:41:07

标签: asp.net structuremap global-asax

我有一个使用内置VS服务器工作正常的自定义HttpModule,但不会从我设置的IIS 7.5服务器运行。 c#文件甚至没有被调用。该模块包含在system.web中,但是当我在system.webserver中添加对模块的另一个引用时,项目将不会加载,并且结构图202异常代码会出错。

我怀疑这个错误的原因与Structuremap启动时有关,但我似乎无法弄明白。我从ObjectFactor文件中的Application_Start初始化global.asax y,它一直正常,直到我尝试加载此模块。

非常感谢任何帮助。

错误是:

 StructureMap Exception Code:  202
No Default Instance defined for PluginFamily testproject.test.Core.DataAccess.IAccountRepository, testproject.test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +23
   System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +60
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +231
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1365
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +95
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9090876
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

更新 - 如果我在我试图调用的模块中初始化对象工厂,则网站会再次加载并且处理程序正常工作。然而,当在加载的每个页面上调用以下内容时,它似乎效率低下并且是不必要的。之前,我能够在全局文件的application_start中加载一次。

            ObjectFactory.Initialize(x =>
        {
            x.UseDefaultStructureMapConfigFile = true;
        });

0 个答案:

没有答案