From bfd185906c871c3ebf11b87d21bb488f18409f87 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 6 Jul 2023 22:19:40 -0700 Subject: [PATCH] Context was updated to support identity --- Newsbot.Collector.Database/DatabaseContext.cs | 55 ++++++++++++------- .../Newsbot.Collector.Database.csproj | 1 + 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Newsbot.Collector.Database/DatabaseContext.cs b/Newsbot.Collector.Database/DatabaseContext.cs index d48c067..c4d8710 100644 --- a/Newsbot.Collector.Database/DatabaseContext.cs +++ b/Newsbot.Collector.Database/DatabaseContext.cs @@ -1,3 +1,5 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newsbot.Collector.Domain.Consts; @@ -5,7 +7,7 @@ using Newsbot.Collector.Domain.Entities; namespace Newsbot.Collector.Database; -public class DatabaseContext : DbContext +public class DatabaseContext : IdentityDbContext { public DbSet Articles { get; set; } = null!; public DbSet DiscordQueue { get; set; } = null!; @@ -13,38 +15,51 @@ public class DatabaseContext : DbContext public DbSet Icons { get; set; } = null!; public DbSet Sources { get; set; } = null!; public DbSet Subscriptions { get; set; } = null!; - - private string ConnectionString { get; set; } - public DatabaseContext(IConfiguration appsettings, string connectionString) - { - var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database); - ConnectionString = connString ?? ""; - } + //public DbSet Users { get; set; } = null!; + + private string ConnectionString { get; set; } = ""; + + //public DatabaseContext(IConfiguration appsettings, string connectionString) + //{ + // var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database); + // ConnectionString = connString ?? ""; + //} public DatabaseContext(string connectionString) { ConnectionString = connectionString; } - public DatabaseContext(DbContextOptions connectionString) - { - ConnectionString = ""; - } - - public DatabaseContext() - { - ConnectionString = ""; - } - protected override void OnConfiguring(DbContextOptionsBuilder options) { - options.UseNpgsql(ConnectionString); + if (ConnectionString != "") + { + options.UseNpgsql(ConnectionString); + } + } + + //public DatabaseContext(DbContextOptions connectionString) + //{ + // ConnectionString = ""; + //} + + //public DatabaseContext() + //{ + // ConnectionString = ""; + //} + + + public DatabaseContext(DbContextOptions options) + : base(options) + { + //ConnectionString = ""; + } public DatabaseContext(DbContextOptions options, string connectionString) : base(options) { - ConnectionString = connectionString; + //ConnectionString = connectionString; } } \ No newline at end of file diff --git a/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj index efbaba5..68f1436 100644 --- a/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj +++ b/Newsbot.Collector.Database/Newsbot.Collector.Database.csproj @@ -6,6 +6,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive