using Microsoft.EntityFrameworkCore;
using OliverBooth.Data.Web;
using OliverBooth.Data.Web.Configuration;
namespace OliverBooth.Data;
///
/// Represents a session with the web database.
///
public sealed class WebContext : DbContext
{
private readonly IConfiguration _configuration;
///
/// Initializes a new instance of the class.
///
/// The configuration.
public WebContext(IConfiguration configuration)
{
_configuration = configuration;
}
///
/// Gets the set of article templates.
///
/// The set of article templates.
public DbSet ArticleTemplates { get; private set; } = null!;
///
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connectionString = _configuration.GetConnectionString("Web") ?? string.Empty;
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
optionsBuilder.UseMySql(connectionString, serverVersion);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new ArticleTemplateConfiguration());
}
}