0
我有以下几点:Autofac覆盖注入
containerBuilder.RegisterType<CustomContext>()
.As<CustomContext>()
.InstancePerLifetimeScope();
containerBuilder.RegisterType<CustomContext>()
.As<BaseContext>()
.InstancePerLifetimeScope();
public class BaseContext : DbContext
{
}
public class CustomContext : BaseContext
{
}
我所试图实现的是,每当BaseContext
在服务的构造函数注入来传递使用containerBuilder.RegisterType<CustomContext>().As<CustomContext>().InstancePerLifetimeScope();
,而不是创建创建的CustomContext
实例一个新的。
目前,无论何时创建生命周期范围,我都有两个CustomContext
左右的实例。
是!这正是我正在寻找的。感谢您阅读这个问题。 – pantonis