Finbuckle.MultiTenant
Finbuckle.MultiTenant copied to clipboard
Guidance for using library in background tasks and services
What's the recommended approach for consuming the library in IHostedService / BackgroundService?
The user will be submitting a job to a queue, including their tenant identifier.
I wish to retrieve the custom ITenantInfo from the database, as it holds connection string and web api service urls.
Seems like it's as simple as using EFCoreStoreDbContext<MyCustomTenantInfo> and a simple query to retrieve.
_ctx.TenantInfo.FirstOrDefaultAsync(x => x.Identifier == identifier)
Am I missing out on anything going this route?
@jeremysimmons in this case I recommend emulating what the middleware does. Assuming you are using DI with the hosted service and configure the library normally you can use this logic in the appropriate place to resolve your tenant. You'll probably need a custom multi tenant strategy or use the delegate strategy:
var resolver = context.RequestServices.GetRequiredService<ITenantResolver>();
var multiTenantContext = await resolver.ResolveAsync(context);
This issue has been automatically marked for closure because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.