-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decorating EF Core's DbContext #148
Comments
Hmm, yeah, that's a tricky one. You're essentially decorating a concrete registration as opposed to an interface registration 🤔 I think what's causing the hang might be the injected The rule of thumb should basically be that you should inject the exact same type as you decorate. That means you probably should inject I haven't really tried this scenario myself, but I can't see why it shouldn't work 😅 |
If you meant like this: public class AuditLogDbContextDecorator<TContext> : DbContext where TContext : DbContext
{
private readonly TContext _decorated;
public AuditLogDbContextDecorator(TContext decorated)
{
_decorated = decorated;
}
} and register like this builder.Services.Decorate(typeof(MyContext), typeof(AuditLogDbContextDecorator<MyContext>)); this doesn't work either :( still hangs |
Hmm, yeah, that's exactly what I meant 😅 I'm not really sure what's going on. Need to take a look at this and do some debugging... |
Closed by #155 |
Hi!
I am currently trying this library for DB audit logging.
I currently have it working for MongoDB - I am using
IMongoRepository
here.But is there any way to decorate EF Core's DbContext too?
I tried this decorator
and decorated it like this:
builder.Services.Decorate(typeof(DbContext), typeof(AuditLogDbContextDecorator));
but this fails with
When I decorate my context implementation:
builder.Services.Decorate(typeof(MyContext), typeof(AuditLogDbContextDecorator));
it works, but then it (probably) deadlocks when I want to retrieve my context either in constructor or by
GetService<MyContext>()
. No error, no exception, it just hangs. Even Ctrl + C won't stop the app, I have to close it using the stop button in VS.Do you know what can be causing this? I was thinking about circular dependency, could it be? Is it even possible to decorate partial abstract class like DbContext?
The text was updated successfully, but these errors were encountered: