feat: auto-create inventory records for new products + migration worker
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m52s

- CreateNewProductsCommandHandler: inject IInventoryService, auto-init
  inventory record with qty=0 when a new regular product is created
  (DiscountProduct handler already had this)
- InventoryInitializerService: one-time BackgroundService that runs on
  startup, finds existing products without InventoryItem records, and
  creates them (migration for legacy products)
- Register InventoryInitializerService in DI
This commit is contained in:
masoodafar-web
2026-02-18 00:42:41 +03:30
parent fd24dcebcd
commit bc710fdb7b
3 changed files with 174 additions and 0 deletions
@@ -123,6 +123,9 @@ public static class ConfigureServices
// Expire pending discount orders after 30 minutes
services.AddHostedService<ExpirePendingOrdersService>();
// One-time: Initialize inventory records for existing products
services.AddHostedService<InventoryInitializerService>();
if (configuration.GetValue<bool>("UseInMemoryDatabase"))
{
services.AddDbContext<ApplicationDbContext>(options =>