hii*_*t95 -1 .net c# dependency-injection autofac winforms
我使用 Autofac 创建一个带有 DependencyInjection 的项目 WindowsForm 应用程序。我在构建时遇到问题。这是我的Program.cs
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerDependency();
builder.RegisterType<DbFactory>().As<IDbFactory>().InstancePerDependency();
builder.RegisterType<DITestDbContext>().AsSelf().InstancePerDependency();
// 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>());
Run Code Online (Sandbox Code Playgroud)
我遇到一条错误消息
DependencyResolutionException:激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = ProductCategoryService (ReflectionActivator)、服务 = [DITest.Service.IProductCategoryService]、生命周期 = Autofac.Core.Lifetime.CurrentScopeLifetime、共享 = None、所有权 = OwnedByLifetimeScope
和
DependencyResolutionException:激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = UnitOfWork (ReflectionActivator),服务 = [DITest.Data.Infrastruct.IUnitOfWork],生命周期 = Autofac.Core.Lifetime.CurrentScopeLifetime,共享 = None,所有权 = OwnedByLifetimeScope
和
NoConstructorsFoundException:找不到类型“DITest.Data.Infrastruct.UnitOfWork”的可访问构造函数。
有人知道怎么修这个东西吗。感谢您!!
UnitOfWork
可能没有公共构造函数,但您没有发布它的代码。
归档时间: |
|
查看次数: |
7767 次 |
最近记录: |