Oliver Booth
e8bc50bbdf
I'd ideally like to keep the blog. subdomain the same, and while there are a few ways to achieve this it is much simpler to just dedicate a separate application for the subdomain. This change also adjusts the webhost builder extensions to default to ports 443/80, and each app now explicitly sets the port it needs.
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using OliverBooth.Blog.Data.Configuration;
|
|
|
|
namespace OliverBooth.Blog.Data;
|
|
|
|
/// <summary>
|
|
/// Represents a session with the blog database.
|
|
/// </summary>
|
|
internal sealed class BlogContext : DbContext
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="BlogContext" /> class.
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration.</param>
|
|
public BlogContext(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the collection of blog posts in the database.
|
|
/// </summary>
|
|
/// <value>The collection of blog posts.</value>
|
|
public DbSet<BlogPost> BlogPosts { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// Gets the collection of users in the database.
|
|
/// </summary>
|
|
/// <value>The collection of users.</value>
|
|
public DbSet<User> Users { get; private set; } = null!;
|
|
|
|
/// <inheritdoc />
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
string connectionString = _configuration.GetConnectionString("Blog") ?? string.Empty;
|
|
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
|
|
optionsBuilder.UseMySql(connectionString, serverVersion);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.ApplyConfiguration(new BlogPostConfiguration());
|
|
modelBuilder.ApplyConfiguration(new UserConfiguration());
|
|
}
|
|
}
|