MultiTenantDbContext constructor with ITenantInfo in V9.0
Hi, I'm having trouble upgrading to 9.0. We were using the constructor of MultiTenantDbContext with parameter ITenantInfo. This was removed. I understand the replacement would be to use the method MultiTenantDbContext.Create, but this fails with "'The provided DbContext type does not have a constructor that accepts the required parameters.'", because our DBContext has additional parameters in its constructor. Any idea how to work arround this? Thanks, Anca
Hello, can you post what your db context constructor does look like?
Some of our DB tables have audit columns like CreatedBy, CreatedOn, ModifiedBy, etc. We have a base DbContext that sets the audit columns to the current user's ID and current time stamp on SaveChanges, it looks like this:
public class MultitenancyAuditDbContext : MultiTenantDbContext
{
protected readonly ICurrentUser _currentUser;
protected MultitenancyAuditDbContext(ITenantInfo tenantInfo, DbContextOptions options, ICurrentUser currentUser) : base(tenantInfo, options) { _currentUser = currentUser; }
[...]
}
Ok I will be adding more support for the Create factory method in the next release (a week or two). All it does is create a static IMultiTenantContextAccessor with the desired tenant and create the db context with it. If you need a quick workaround take a loo at that function and make one similar that also includes your DI needs.
Just put out a release with more factory methods including one that can take arbitrary dependency instances as well as as service provider. Let me know if that helps.
Thank you, I will get back to you next week, when I have the chance to upgrade. Meanwhile I created my own factory method.
Sorry for the delay, I could update today and it is better now, thank you!