Update to latest version and show additional features
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using GerstITS.Data.EntityFramework;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GerstITS.Examples.JobDashboard.Data;
|
||||
|
||||
public sealed class JobRunDbContext : EntityFrameworkDbContextBase, IDbContext
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public DbSet<JobRunEntity> JobRuns => Set<JobRunEntity>();
|
||||
|
||||
protected override string ConnectionStringName => "JobRunDbContext";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public JobRunDbContext(IDatabaseConfigurator databaseConfigurator,
|
||||
DbContextOptions<JobRunDbContext> dbContextOptions)
|
||||
: base(databaseConfigurator, dbContextOptions)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using GerstITS.Data;
|
||||
|
||||
namespace GerstITS.Examples.JobDashboard.Data;
|
||||
|
||||
public sealed class JobRunEntity : EntityBase<int>
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public string JobName { get; set; }
|
||||
public DateTimeOffset StartedAt { get; set; }
|
||||
public long DurationMilliseconds { get; set; }
|
||||
public bool Success { get; set; }
|
||||
public string Error { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using GerstITS.Data.EntityFramework;
|
||||
|
||||
namespace GerstITS.Examples.JobDashboard.Data;
|
||||
|
||||
/// <summary>
|
||||
/// The EF Core module registers an auto-migration startup task that requires an
|
||||
/// <see cref="IEntityFrameworkMigrationConfiguration" />. The InMemory provider has no migrations, so
|
||||
/// this implementation simply disables auto-migration.
|
||||
/// </summary>
|
||||
public sealed class NoDatabaseMigrationConfiguration : IEntityFrameworkMigrationConfiguration
|
||||
{
|
||||
#region IEntityFrameworkMigrationConfiguration
|
||||
|
||||
public bool AutoMigrate => false;
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user