Allow user to use DbContext pooling with Quartz (#5625)
This commit is contained in:
parent
5a1306d14e
commit
29074336f2
|
|
@ -18,13 +18,12 @@ public static class MySqlQuartzExtensions
|
|||
/// <summary>
|
||||
/// Configures the <see cref="QuartzFeature"/> to use the MySQL job store.
|
||||
/// </summary>
|
||||
public static QuartzFeature UseMySql(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true)
|
||||
public static QuartzFeature UseMySql(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true, bool useContextPooling = false)
|
||||
{
|
||||
feature.Services.AddDbContextFactory<MySqlQuartzDbContext>(options =>
|
||||
{
|
||||
// Use MySQL migrations.
|
||||
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(MySqlQuartzDbContext).Assembly.GetName().Name); });
|
||||
});
|
||||
if (useContextPooling)
|
||||
feature.Services.AddPooledDbContextFactory<MySqlQuartzDbContext>(options => UseMySql(connectionString, options));
|
||||
else
|
||||
feature.Services.AddDbContextFactory<MySqlQuartzDbContext>(options => UseMySql(connectionString, options));
|
||||
|
||||
feature.ConfigureQuartz += quartz =>
|
||||
{
|
||||
|
|
@ -32,7 +31,7 @@ public static class MySqlQuartzExtensions
|
|||
{
|
||||
store.UseNewtonsoftJsonSerializer();
|
||||
store.UseMySqlConnector(options => options.ConnectionString = connectionString);
|
||||
|
||||
|
||||
if (useClustering)
|
||||
store.UseClustering();
|
||||
});
|
||||
|
|
@ -43,4 +42,10 @@ public static class MySqlQuartzExtensions
|
|||
|
||||
return feature;
|
||||
}
|
||||
|
||||
private static void UseMySql(string connectionString, DbContextOptionsBuilder options)
|
||||
{
|
||||
// Use MySQL migrations.
|
||||
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(MySqlQuartzDbContext).Assembly.GetName().Name); });
|
||||
}
|
||||
}
|
||||
|
|
@ -18,13 +18,12 @@ public static class PostgreSqlQuartzExtensions
|
|||
/// <summary>
|
||||
/// Configures the <see cref="QuartzFeature"/> to use the PostgreSQL job store.
|
||||
/// </summary>
|
||||
public static QuartzFeature UsePostgreSql(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true)
|
||||
public static QuartzFeature UsePostgreSql(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true, bool useContextPooling = false)
|
||||
{
|
||||
feature.Services.AddDbContextFactory<PostgreSqlQuartzDbContext>(options =>
|
||||
{
|
||||
// Use PostgreSQL migrations.
|
||||
options.UseNpgsql(connectionString, sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(PostgreSqlQuartzDbContext).Assembly.GetName().Name); });
|
||||
});
|
||||
if (useContextPooling)
|
||||
feature.Services.AddPooledDbContextFactory<PostgreSqlQuartzDbContext>(options => UseNpgsql(connectionString, options));
|
||||
else
|
||||
feature.Services.AddDbContextFactory<PostgreSqlQuartzDbContext>(options => UseNpgsql(connectionString, options));
|
||||
|
||||
feature.ConfigureQuartz += quartz =>
|
||||
{
|
||||
|
|
@ -48,4 +47,10 @@ public static class PostgreSqlQuartzExtensions
|
|||
|
||||
return feature;
|
||||
}
|
||||
|
||||
private static void UseNpgsql(string connectionString, DbContextOptionsBuilder options)
|
||||
{
|
||||
// Use PostgreSQL migrations.
|
||||
options.UseNpgsql(connectionString, sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(PostgreSqlQuartzDbContext).Assembly.GetName().Name); });
|
||||
}
|
||||
}
|
||||
|
|
@ -18,13 +18,12 @@ public static class SqlServerQuartzExtensions
|
|||
/// <summary>
|
||||
/// Configures the <see cref="QuartzFeature"/> to use the SQL Server job store.
|
||||
/// </summary>
|
||||
public static QuartzFeature UseSqlServer(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true)
|
||||
public static QuartzFeature UseSqlServer(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useClustering = true, bool useContextPooling = false)
|
||||
{
|
||||
feature.Services.AddDbContextFactory<SqlServerQuartzDbContext>(options =>
|
||||
{
|
||||
// Use SQL Server migrations.
|
||||
options.UseSqlServer(connectionString, sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(SqlServerQuartzDbContext).Assembly.GetName().Name); });
|
||||
});
|
||||
if (useContextPooling)
|
||||
feature.Services.AddPooledDbContextFactory<SqlServerQuartzDbContext>(options => UseSqlServer(connectionString, options));
|
||||
else
|
||||
feature.Services.AddDbContextFactory<SqlServerQuartzDbContext>(options => UseSqlServer(connectionString, options));
|
||||
|
||||
feature.ConfigureQuartz += quartz =>
|
||||
{
|
||||
|
|
@ -48,4 +47,10 @@ public static class SqlServerQuartzExtensions
|
|||
|
||||
return feature;
|
||||
}
|
||||
|
||||
private static void UseSqlServer(string connectionString, DbContextOptionsBuilder options)
|
||||
{
|
||||
// Use SQL Server migrations.
|
||||
options.UseSqlServer(connectionString, sqlServerDbContextOptionsBuilder => { sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(SqlServerQuartzDbContext).Assembly.GetName().Name); });
|
||||
}
|
||||
}
|
||||
|
|
@ -18,13 +18,12 @@ public static class SqliteQuartzExtensions
|
|||
/// <summary>
|
||||
/// Configures the <see cref="QuartzFeature"/> to use the SQLite job store.
|
||||
/// </summary>
|
||||
public static QuartzFeature UseSqlite(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString)
|
||||
public static QuartzFeature UseSqlite(this QuartzFeature feature, string connectionString = Constants.DefaultConnectionString, bool useContextPooling = false)
|
||||
{
|
||||
feature.Services.AddDbContextFactory<SqliteQuartzDbContext>(options =>
|
||||
{
|
||||
// Use SQLite migrations.
|
||||
options.UseSqlite(connectionString, sqlite => { sqlite.MigrationsAssembly(typeof(SqliteQuartzDbContext).Assembly.GetName().Name); });
|
||||
});
|
||||
if (useContextPooling)
|
||||
feature.Services.AddPooledDbContextFactory<SqliteQuartzDbContext>(options => UseSqlite(connectionString, options));
|
||||
else
|
||||
feature.Services.AddDbContextFactory<SqliteQuartzDbContext>(options => UseSqlite(connectionString, options));
|
||||
|
||||
feature.ConfigureQuartz += quartz =>
|
||||
{
|
||||
|
|
@ -40,4 +39,10 @@ public static class SqliteQuartzExtensions
|
|||
|
||||
return feature;
|
||||
}
|
||||
|
||||
private static void UseSqlite(string connectionString, DbContextOptionsBuilder options)
|
||||
{
|
||||
// Use SQLite migrations.
|
||||
options.UseSqlite(connectionString, sqlite => { sqlite.MigrationsAssembly(typeof(SqliteQuartzDbContext).Assembly.GetName().Name); });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue