C# 更改RegisterType中的生存期管理器时,Unity IoC操作无效
我在MVC4项目中为我的IoC和Unity配置了这个配置C# 更改RegisterType中的生存期管理器时,Unity IoC操作无效,c#,asp.net-mvc,unity-interception,C#,Asp.net Mvc,Unity Interception,我在MVC4项目中为我的IoC和Unity配置了这个配置 container.RegisterType<IDbContext, ConstructionRepositoryContext>("ConstructionRepositoryContext", new TransientLifetimeManager()); container.RegisterType<IDbContext, GeneralRepositoryContext>("GeneralReposito
container.RegisterType<IDbContext, ConstructionRepositoryContext>("ConstructionRepositoryContext", new TransientLifetimeManager());
container.RegisterType<IDbContext, GeneralRepositoryContext>("GeneralRepositoryContext", new TransientLifetimeManager());
container.RegisterType<IUnitOfWork, UnitOfWork>(
"ConstructionUnitOfWork",
new InjectionConstructor(container.Resolve<IDbContext>("ConstructionRepositoryContext")));
container.RegisterType<IUnitOfWork, UnitOfWork>(
"GeneralUnitOfWork",
new InjectionConstructor(container.Resolve<IDbContext>("GeneralRepositoryContext")));
异常可能在此行引发:
container.Resolve<IDbContext>("ConstructionRepositoryContext"))
这会告诉容器:
解析名为“ConstructionUnitOfWork”的
UnitOfWork
时,请使用接受单个IDbContext
参数的构造函数,解析该参数时,请使用名称“ConstructionRepositoryContext”进行解析
如何解析IUnitofWork
的容器?看起来我错了,InjectionConstructor
没有被弃用。删除了以前的评论。
container.Resolve<IDbContext>("ConstructionRepositoryContext"))
container.RegisterType<IUnitOfWork, UnitOfWork>(
"ConstructionUnitOfWork",
new InjectionConstructor(new ResolvedParameter<IDbContext>("ConstructionRepositoryContext")));