-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating Mellon.MultiTenant with Hangfire in ASP.NET Core #29
Comments
Currently, there is no way to load the tenants from a database, I was thinking about adding this feature, might be a good time to do so...😍 To use Hangfire with Mellon, you need only to do a few things during the services configuration builder.Services
.AddMultiTenant()
.AddMultiTenantHangfire(); builder.Services.AddHangfire((serviceProvider, config) =>
{
// some code
config.UseMultiTenant(serviceProvider);
// some code
}); and you will have two options if you want to have one queue per tenant you will need to create a Job interface like this [Queue("tenant-name")]
public interface IMySuperNiceJob
{
} this will move the job when is about to be executed to a queue with the tenant name if not, once the job is created, the library will add a property to the job indicating the tenant for that particular job execution and all services will respect that accordingly PS: sorry for the delay @ShahramNo... |
I created this issue here to address your request @ShahramNo |
Hi, Thank you for the detailed explanation. I have a follow-up question regarding loading tenants from a database. Given my current setup where I store all tenant information in a database, how can I configure Mellon.MultiTenant to dynamically load and manage tenants with Hangfire, ensuring that each tenant's specific connection string is used? Here's a brief overview of my setup: Connection Strings:
Tenant Model: `
` `
} Tenant Resolution Middleware: public class TenantResolutionMiddleware
} ` Tenant Database Initializer: ` public static class TenantDatabaseInitializer
} ` Service Configuration: ` public static class ServiceCollectionExtensions
} ` Given this setup, how can I implement Mellon.MultiTenant to dynamically load tenants from the database and ensure that Hangfire uses the correct connection string for each tenant? Is this currently possible with Mellon.MultiTenant, and if so, could you provide an example or additional guidance? Thank you in advance for your assistance! |
Hi,
I'm trying to integrate Mellon.MultiTenant into my existing multi-tenant setup with Hangfire. Could you provide guidance or examples on how to properly configure Mellon.MultiTenant with Hangfire? Specifically, I'm looking for help on how to ensure that Hangfire uses the correct connection string for each tenant.
I have 2 connection strings, Web is my default connection string when a tenant is not available, and Tenant stores all connection strings for every tenant, and i store all tenant in database,
Thank you in advance for your assistance!
appsetting:
{ "ConnectionStrings": { "Web": "Server=xxxx", "Tenant": "Server=xxx" } }
TenantModel:
`
```
public class Tenant : BaseEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public string? Host { get; set; }
public string SubDomain { get; set; } = null!;
public string ConnectionString { get; set; }
}
TenantResolutionMiddleware:
app.UseMiddleware<TenantResolutionMiddleware>();
` public class TenantResolutionMiddleware
{
private readonly RequestDelegate _next;
}`
InitializeTenantDatabases Middleware:
app.InitializeTenantDatabase(); app.InitializeTenantDatabases();
`public static class TenantDatabaseInitializer
{
public static void InitializeTenantDatabases(this WebApplication app)
{
using var scope = app.Services.CreateScope();
var tenantService = scope.ServiceProvider.GetRequiredService();
}
`
Tenant Services:
builder.Services.AddTenantServices(builder.Configuration); builder.Services.AddDynamicDbContexts(builder.Configuration);
`public static class ServiceCollectionExtensions
{
public static IServiceCollection AddTenantServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext(options =>
options.UseSqlServer(configuration.GetConnectionString("Tenant")));
}`
The text was updated successfully, but these errors were encountered: