I have an interface for Audit Logging:
public interface IAuditDbContext<T1, T2>
{
T1 AuditLog { get; set; }
T2 ChangeTracker { get; }
}
now in main AppDbContext interface, I am inheriting this as:
public interface IAppDBContext<T1, T2> : IAuditDbContext<T1,T2>
{
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
}
and in main AppDbContext class, I am inheriting as:
public class AppDBContext : DbContext, IAppDBContext<DbSet<Audit>, ChangeTracker>
{
....
}
The problem is, at the time of Dependency Injection, I am trying to inject it like:
services.AddScoped(
typeof(IAppDBContext<,>),
typeof(IAuditDbContext<,>).MakeGenericType(typeof(AppDBContext)));
I have tried other ways as well, but not able to get the success - some error messages that I am getting are:
Error Messages:
- Message=The number of generic arguments provided doesn't equal the arity of the generic type definition.
- Cannot instantiate implementation type 'Common.Application.Interfaces. IAuditDbContext
2[T1,T2]' for service type 'Common.Application.Interfaces.IAppDBContext
2[T1,T2]'
Requesting help to implement it correctly.