bakery-erp / src /BakeryErp.Web /Program.cs
Neil67's picture
Deploy Bakery ERP Space
13240d3
Raw
History Blame Contribute Delete
2.26 kB
using BakeryErp.Infrastructure.Database;
using BakeryErp.Infrastructure.Repositories;
using BakeryErp.Infrastructure.Services;
using BakeryErp.Web;
var builder = WebApplication.CreateBuilder(args);
var databaseDirectory = builder.Configuration["BakeryErp:DataDirectory"]
?? Environment.GetEnvironmentVariable("BAKERY_ERP_DATA_DIR")
?? Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".bakery-erp");
Directory.CreateDirectory(databaseDirectory);
var databasePath = Path.Combine(databaseDirectory, "bakery-erp.local.json");
var attachmentDirectory = Path.Combine(databaseDirectory, "attachments");
Directory.CreateDirectory(attachmentDirectory);
var databaseOptions = new DatabaseOptions
{
DatabasePath = databasePath
};
builder.Services.AddRazorPages();
builder.Services.AddSingleton(databaseOptions);
builder.Services.AddSingleton<DatabaseInitializer>();
builder.Services.AddScoped<DashboardRepository>();
builder.Services.AddScoped<SupplierRepository>();
builder.Services.AddScoped<ItemRepository>();
builder.Services.AddScoped<StoreRepository>();
builder.Services.AddScoped<WarehouseRepository>();
builder.Services.AddScoped<MasterDataLookupRepository>();
builder.Services.AddScoped<OcrDocumentRepository>();
builder.Services.AddScoped<InventoryRepository>();
builder.Services.AddScoped<PurchaseRepository>();
builder.Services.AddScoped<PettyCashRepository>();
builder.Services.AddScoped<TransferRepository>();
builder.Services.AddScoped<StoreReturnRepository>();
builder.Services.AddScoped<ReportCenterRepository>();
builder.Services.AddScoped<OcrSmartParser>();
builder.Services.AddHttpClient<OpenAiVisionOcrService>();
builder.Services.AddSingleton(new AppRuntimeInfo(databasePath));
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
scope.ServiceProvider.GetRequiredService<DatabaseInitializer>().Initialize();
}
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
attachmentDirectory),
RequestPath = "/attachments"
});
app.UseRouting();
app.MapRazorPages();
app.Run();