I have the following on an ASP.NET Core application Startup:
services.AddDbContext<Context>(x => x.UseSqlServer(connectionString));
services.AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining<Startup>());
When I inject Entity Framework context on a FluentValidation validator:
public class TestModelValidator : AbstractValidator<TestModel> {
public TestModelValidator(Context context) {
}
}
I get the following error:
ObjectDisposedException: Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur is you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: Context
What am I missing?