Init
This commit is contained in:
50
Prefab.Catalog.Api/Module.cs
Normal file
50
Prefab.Catalog.Api/Module.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Prefab.Catalog.Data;
|
||||
using Prefab.Catalog.Api.Data;
|
||||
using Prefab.Data;
|
||||
using Prefab.Module;
|
||||
|
||||
namespace Prefab.Catalog.Api;
|
||||
|
||||
public class Module : IModule
|
||||
{
|
||||
public WebApplicationBuilder Build(WebApplicationBuilder builder)
|
||||
{
|
||||
var writeConnection = builder.Configuration.GetConnectionString("PrefabDb")
|
||||
?? throw new InvalidOperationException("Connection string 'PrefabDb' not found. Ensure the Aspire AppHost exposes the SQL resource.");
|
||||
var readConnection = builder.Configuration.GetConnectionString("PrefabDbReadOnly") ?? writeConnection;
|
||||
|
||||
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
builder.Services.AddDbContext<IPrefabDb, AppDb>(options =>
|
||||
options.UseSqlServer(writeConnection, sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
||||
|
||||
builder.Services.AddDbContext<IPrefabDbReadOnly, AppDbReadOnly>(options =>
|
||||
options.UseSqlServer(readConnection, sqlOptions => sqlOptions.EnableRetryOnFailure()));
|
||||
|
||||
builder.Services.AddDbContextFactory<AppDb>(options =>
|
||||
options.UseSqlServer(writeConnection, sqlOptions => sqlOptions.EnableRetryOnFailure()), ServiceLifetime.Scoped);
|
||||
|
||||
builder.Services.AddDbContextFactory<AppDbReadOnly>(options =>
|
||||
options.UseSqlServer(readConnection, sqlOptions => sqlOptions.EnableRetryOnFailure()), ServiceLifetime.Scoped);
|
||||
|
||||
builder.Services.AddModuleDbInterfaces(typeof(AppDb));
|
||||
builder.Services.AddModuleDbInterfaces(typeof(AppDbReadOnly));
|
||||
|
||||
builder.Services.AddScoped<ICatalogDbContextFactory, CatalogDbContextFactory>();
|
||||
|
||||
//builder.Services.AddHostedService<DataSeeder>();
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
public WebApplication Configure(WebApplication app)
|
||||
{
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user