Skip to content

Commit

Permalink
upgrade to overridable ef db mix
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 6, 2024
1 parent 5d5cc4b commit 1b35305
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
21 changes: 14 additions & 7 deletions MyApp/Configure.Db.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;
using ServiceStack.Data;
using ServiceStack.OrmLite;
using MyApp.Data;

[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]

Expand All @@ -9,13 +11,18 @@ public class ConfigureDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
var connectionString = context.Configuration.GetConnectionString("DefaultConnection")
?? "DataSource=App_Data/app.db;Cache=Shared";

services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
context.Configuration.GetConnectionString("DefaultConnection")
?? ":memory:",
SqliteDialect.Provider));
})
.ConfigureAppHost(appHost => {
connectionString, SqliteDialect.Provider));

// $ dotnet ef migrations add CreateIdentitySchema
// $ dotnet ef database update
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp))));

// Enable built-in Database Admin UI at /admin-ui/database
appHost.Plugins.Add(new AdminDatabaseFeature());
services.AddPlugin(new AdminDatabaseFeature());
});
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MyApp/Migrations/ApplicationDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ partial class ApplicationDbContextModelSnapshot : ModelSnapshot
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.0-rc.2.23480.1");
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");

modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
Expand Down
5 changes: 0 additions & 5 deletions MyApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("App_Data"));

// $ dotnet ef migrations add CreateIdentitySchema
// $ dotnet ef database update
var connectionString = config.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(connectionString, b => b.MigrationsAssembly(nameof(MyApp))));
services.AddDatabaseDeveloperPageExceptionFilter();

services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
Expand Down

0 comments on commit 1b35305

Please sign in to comment.