You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to Finbuckle, and also relatively new to ASP.NET Core and dependency injection, so this suggestion may not be helpful. Please let me know!
I am working on implementing multitenant behavior in a web site that uses separate databases for tenant isolation. In the current docs, it is suggested to use the following constructor on the sample EF context class, MyAppDbContext.
public MyAppDbContext(IMultiTenantContextAccessor<AppTenantInfo> multiTenantContextAccessor)
{
// get the current tenant info at the time of construction
TenantInfo = multiTenantContextAccessor.tenantInfo;
}
When I tried the sample approach, the dependency injection framework complained about ambiguous constructors. It didn't like that I had this constructor on my class.
public MyAppDbContext(DbContextOptions<MyAppDbContext> options)
: base(options)
{ }
As I understand EF Core, this is a pretty standard constructor. In my project, the EF Context class is used in multiple projects, and these other projects are using the DbContextOptions constructor.
The solution I found for this situation was to handle the multi-tenant configuration for the connection string while building the services. Between the builder.Services.AddMultiTenant<> line and the app.UseMultiTenant() line, the DbContext is configured like this:
builder.Services.AddDbContext<MyAppDbContext>((serviceProvider, dbContextBuilder)=>
{
var tenantAccessor = serviceProvider.GetRequiredService<IMultiTenantContextAccessor<AppTenantInfo>>();
dbContextBuilder.UseSqlServer(
tenantAccessor.MultiTenantContext.TenantInfo.ConnectionString);
});
I wonder if this is even a good way of handling this situation, given my newbie status to these concepts. If it is a good solution, would this information be useful to be added to the documentation as an alternative to using the IMultiTenantContextAccessor constructor and the OnConfiguring method?
The text was updated successfully, but these errors were encountered:
I'm new to Finbuckle, and also relatively new to ASP.NET Core and dependency injection, so this suggestion may not be helpful. Please let me know!
I am working on implementing multitenant behavior in a web site that uses separate databases for tenant isolation. In the current docs, it is suggested to use the following constructor on the sample EF context class,
MyAppDbContext
.When I tried the sample approach, the dependency injection framework complained about ambiguous constructors. It didn't like that I had this constructor on my class.
As I understand EF Core, this is a pretty standard constructor. In my project, the EF Context class is used in multiple projects, and these other projects are using the
DbContextOptions
constructor.The solution I found for this situation was to handle the multi-tenant configuration for the connection string while building the services. Between the
builder.Services.AddMultiTenant<>
line and theapp.UseMultiTenant()
line, theDbContext
is configured like this:I wonder if this is even a good way of handling this situation, given my newbie status to these concepts. If it is a good solution, would this information be useful to be added to the documentation as an alternative to using the
IMultiTenantContextAccessor
constructor and theOnConfiguring
method?The text was updated successfully, but these errors were encountered: