我正在将我的ASP.Net应用程序从MC3转换为MVC4。我有来自旧MVC3天的Simpleinjector代码,如下所示
WebContainer.Instance.Container.GetInstance<Func<HttpRequestBase>>();
现在这行代码在新的SimpleInjector版本2.8.0中抛出异常。我的应用程序在.Net framework 4.0中。请告知下面的堆栈跟踪
Message: No registration for type Func could be found.
Exception type: SimpleInjector.ActivationException
Stack Trace:
at SimpleInjector.Container.ThrowMissingInstanceProducerException(Type serviceType)
at SimpleInjector.Container.GetInstance[TService]()
at Aon.Exchange.Web.UserControlBase..ctor()
at ASP.cmswebparts_aonexchange_help2_ascx..ctor()
at __ASP.FastObjectFactory_app_web_help2_ascx_f5d8491b_aknegnyf.Create_ASP_cmswebparts_aonexchange_help2_ascx()
at System.Web.UI.TemplateControl.LoadControl(IWebObjectFactory objectFactory, VirtualPath virtualPath, Type t, Object[] parameters)
at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
at CMS.PortalControls.CMSWebPartZone.LoadWebPart(Control container, CMSWebPartZone zone, WebPartInstance part, Boolean reloadData, Boolean isVariant)
WebContainer的代码如下所示
this.Container = new Container();
SimpleInjectorWebInitializer.Initialize();
this.Container.RegisterPackages(GetAssemblies());
this.Container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
this.Container.RegisterMvcIntegratedFilterProvider();
this.RegisterGlobalFilters();
//this.Container.Verify();
DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(this.Container));
//this.VerifyPages();
此功能的注册如下
container.RegisterPerWebRequest<Func<HttpRequestBase>>(() => () => new HttpRequestWrapper(HttpContext.Current.Request));