我收到Microsoft.Practices.Unity.dll
中发生的'System.StackOverflowException'类型的未处理异常public SomeDbContext(IAuditLogService service)
: base("name=SomeDb")
{
}
public static SomeDbContext Create()
{
using (var container = new UnityContainer())
{
var service = container.Resolve<IAuditLogService>();
return new SomeDbContext(service);
}
}
container.RegisterType<DbContext, SomeDbContext>(new TransientLifetimeManager());
container.RegisterType<ISomeDbContext, SomeDbContext>(new TransientLifetimeManager());
container.RegisterType<IAuditLogService, AuditLogService>(new HierarchicalLifetimeManager());
container.RegisterType<IAuditLogManager, AuditLogManager>(new HierarchicalLifetimeManager());
AuditLogService具有以下构造函数:
public AuditLogService(IAuditLogManager auditLogManager)
{
}
和AuditLogManager有:
public AuditLogManager(ISomeDbContext context) : base(context)
{
}
基本上我想在调用SaveChanges()时插入一些日志。我想用DI传递AuditLogService。
我该如何设置?