45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using GerstITS.Data.EntityFramework;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace GerstITS.Examples.JobDashboard.Data;
|
|
|
|
/// <summary>
|
|
/// Configures <see cref="JobRunDbContext" /> to use the EF Core InMemory provider
|
|
/// (<c>UseInMemoryDatabase</c>) so the example runs with zero external database dependencies.
|
|
///
|
|
/// All contexts share the same named in-memory database, so records written by one job execution are
|
|
/// visible to the next. No migrations are involved - the InMemory provider creates the model on demand.
|
|
/// </summary>
|
|
public sealed class InMemoryDatabaseConfigurator : DatabaseConfiguratorBase
|
|
{
|
|
#region Constants
|
|
|
|
private const string DatabaseName = "GerstITS.Examples.JobRuns";
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public InMemoryDatabaseConfigurator(IConfiguration configuration)
|
|
: base(configuration)
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DatabaseConfiguratorBase
|
|
|
|
public override void ConfigureModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
// JobRunEntity is mapped by convention; the InMemory provider needs no relational configuration.
|
|
}
|
|
|
|
protected override void ConfigureDatabase(DbContextOptionsBuilder optionsBuilder, string connectionString)
|
|
{
|
|
optionsBuilder.UseInMemoryDatabase(DatabaseName);
|
|
}
|
|
|
|
#endregion
|
|
}
|