Unity and ASP.NET WebForms - No parameterless constructor defined for this object

匿名 (未验证) 提交于 2019-12-03 02:18:01

问题:

Does anyone have any good examples of how to make Unity 1.2 or 2.0 work with ASP.NET WebForms?

I thought I had this figured out, but evidently I'm missing something. Now I'm getting the error; "No parameterless constructor defined for this object". I remember getting this error a couple years ago, I and just don't remember what I did.

Obviously Unity isn't working as it should because somewhere along the way I've forgotten something. Any help would be appreciated.

Here's some of my code:

Global.asax

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState;  using Microsoft.Practices.Unity;  using PIA35.Unity;  namespace PIA35.Web {     public class Global : System.Web.HttpApplication     {          protected void Application_Start(object sender, EventArgs e)         {             IUnityContainer container = Application.GetContainer();             PIA35.Web.IoC.Bootstrapper.Configure(container);         }     } }

Here's my httpModules section of the web.config file:

<httpModules>     <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>     <add name="UnityHttpModule" type="PIA35.Unity.UnityHttpModule, PIA35.Unity"/> </httpModules> 

Here's the code for my IoC bootstrapper class.

using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Practices.Unity;  using PIA35.Services.Interfaces; using PIA35.Services; using PIA35.DataObjects.Interfaces; using PIA35.DataObjects.SqlServer;  namespace PIA35.Web.IoC {     public static class Bootstrapper     {         public static void Configure(IUnityContainer container)         {             container                 .RegisterType<ICategoryService, CategoryService>()                 .RegisterType<ICustomerService, CustomerService>()                 .RegisterType<IOrderService, OrderService>()                 .RegisterType<IOrderDetailService, OrderDetailService>()                 .RegisterType<IProductService, ProductService>()                 .RegisterType<ICategoryDao, SqlServerCategoryDao>()                 .RegisterType<ICustomerDao, SqlServerCustomerDao>()                 .RegisterType<IOrderDao, SqlServerOrderDao>()                 .RegisterType<IOrderDetailDao, SqlServerOrderDetailDao>()                 .RegisterType<IProductDao, SqlServerProductDao>();         }     } } 

Here's the HttpApplicationStateExtensions.cs file.

using System.Web;  using Microsoft.Practices.Unity;  namespace PIA35.Unity {     public static class HttpApplicationStateExtensions     {         private const string GlobalContainerKey = "GlobalUnityContainerKey";          public static IUnityContainer GetContainer(this HttpApplicationState application)         {             application.Lock();             try             {                 IUnityContainer        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!