Hi,
I have tenants with with separate databases, when hangfire job is executed it uses default host database. How can I force repositories to use specific database for db operations?
**IMMEDIATE RESPONSE IS REQUIRED. **
Thanks
19 Answer(s)
-
0
you want Hangfire to work with tenant databases?
-
0
yes
-
0
For example Tenant A schedules a SMS sending job and this tenant has its own database and this job has nothing to do with Host database and other databases.
-
0
We don't have such an integrated by default.
-
0
Lets keep hangfire a side, how can i force repositories to use a specific DbContext?
For example: By providing a specific connection string in EntityframeworkCoreModule
public override void PreInitialize()
{
if (!SkipDbContextRegistration)
{
Configuration.Modules.AbpEfCore().AddDbContext<MCodeCoreDbContext>(options =>
{
if (options.ExistingConnection != null)
{
MCodeCoreDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
}
else
{
MCodeCoreDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
}
});
}}
-
0
you can create custom repository.
see:https://aspnetboilerplate.com/Pages/Documents/EntityFramework-Integration#custom-repositories -
0
How can I initialize custom repository with specific dbContext (connection string)?
-
0
You can create db context for each custom repository if you have a few connection string.
Steps:
Create dbcontext and then configure them with their connection strings.Then create custom repositories for them
-
0
Can u show me example or some sample code. Thanks
-
0
I don't have an example project but documents has all of them.
see: https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Corecreating db context: https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core#dbcontext
configuring db context: https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core#configuration
creating custom repositories from db context: https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core#custom-repositories -
0
https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core#configuration says that:
"ABP can use IConnectionStringResolver to determine it. This behaviour can be changed and the connection string can be determined dynamically."
I never try it, but i think you should try it before them https://support.aspnetzero.com/QA/Questions/7386#answer-266967fa-ea7f-b56e-03ee-39ef3b733097
-
0
Having jobs in tenant's database would also have better performance impact on database. If there are a lot of tenants in system and background jobs in each tenants are frequent, thare could be a bottleneck on host database.
Consider also this aspect. -
0
I have tried having jobs in respective tenant database but it was not successful, have you tried this?
-
0
My response is for Volosoft (in consideration for better background jobs). :)
-
0
Hi @Mazharmig,
Is this issue resolved for you ?
Thanks,
-
0
I just implemented a work around
-
0
I want every tenant responsible for its job. For that purpose I implemented a HangfireConfigurer that Initializes tenant's hangfire dashboard at startup. I have done this before in my old application that will be replaced by ANZ but I got issue at Controller level, after setting JobStorage Hangfire didn't worked.
-
0
Now I am using Host database for every job (all tenants). I have implemented a ContextJobWorker that picks the job and works in the respective database of tenant.
Any suggestion or correction from your side? -
0
I can't think of a better solution at the moment.