This commit is contained in:
2025-10-27 17:39:18 -04:00
commit 31f723bea4
1579 changed files with 642409 additions and 0 deletions

68
Prefab.Web/Module.cs Normal file
View File

@@ -0,0 +1,68 @@
using Microsoft.EntityFrameworkCore;
using Prefab.Catalog.Data;
using Prefab.Data;
using Prefab.Module;
using Prefab.Web.Client.Services;
using Prefab.Web.Data;
using Prefab.Web.Gateway;
using Prefab.Web.Shared;
using Prefab.Web.Workers;
namespace Prefab.Web;
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>();
builder.Services.AddScoped<INotificationService, NotificationService>();
builder.Services.AddScoped<INavMenuService, Prefab.Web.Gateway.Shared.NavMenu.Service>();
builder.Services.AddScoped<ICategoriesPageService, Categories.PageService>();
builder.Services.AddScoped<Home.Service>();
builder.Services.AddScoped<Products.ListingService>();
builder.Services.AddScoped<IProductListingService>(sp => sp.GetRequiredService<Products.ListingService>());
builder.Services.AddScoped<IHomePageService>(sp => sp.GetRequiredService<Home.Service>());
return builder;
}
public WebApplication Configure(WebApplication app)
{
app.UseExceptionHandling();
return app;
}
}