var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()); // Register your Web API controllers. //builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerDependency(); builder.RegisterType<DbFactory>().As<IDbFactory>().InstancePerDependency(); builder.RegisterType<DITestDbContext>().AsSelf().InstancePerDependency(); //builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest(); // Repositories builder.RegisterAssemblyTypes(typeof(ProductCategoryRepository).Assembly) .Where(t => t.Name.EndsWith("Repository")) .AsImplementedInterfaces().InstancePerDependency(); // Services builder.RegisterAssemblyTypes(typeof(ProductCategoryService).Assembly) .Where(t => t.Name.EndsWith("Service")) .AsImplementedInterfaces().InstancePerDependency(); Autofac.IContainer container = builder.Build(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(container.Resolve<Form1>());
private IProductCategoryService productCategoryService; private IUnitOfWork unitOfWork; public Form1(IProductCategoryService productCategoryService, IUnitOfWork unitOfWork) { this.productCategoryService = productCategoryService; this.unitOfWork = unitOfWork; InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); LoadProductCategory(); } private void LoadProductCategory() { var data = productCategoryService.GetAll(); gridControl1.DataSource = data; }
Quote:'An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = Form1 (ReflectionActivator), Services = [Presentation.Form1], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope'
Quote:NoConstructorsFoundException: No accessible constructors were found for the type 'DITest.Data.Infrastructure.UnitOfWork'.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)