Semplificazione init Repo/Servizi x DI

This commit is contained in:
Samuele Locatelli
2026-03-19 14:36:03 +01:00
parent 1d5e80df53
commit 40193db94f
3 changed files with 103 additions and 196 deletions
+2 -94
View File
@@ -1,19 +1,5 @@
using EgwCoreLib.Lux.Data;
using EgwCoreLib.Lux.Data.Repository.Config;
using EgwCoreLib.Lux.Data.Repository.Cost;
using EgwCoreLib.Lux.Data.Repository.Items;
using EgwCoreLib.Lux.Data.Repository.Job;
using EgwCoreLib.Lux.Data.Repository.Production;
using EgwCoreLib.Lux.Data.Repository.Sales;
using EgwCoreLib.Lux.Data.Repository.Utils;
using EgwCoreLib.Lux.Data.Services;
using EgwCoreLib.Lux.Data.Services.Config;
using EgwCoreLib.Lux.Data.Services.Cost;
using EgwCoreLib.Lux.Data.Services.Items;
using EgwCoreLib.Lux.Data.Services.Job;
using EgwCoreLib.Lux.Data.Services.Production;
using EgwCoreLib.Lux.Data.Services.Sales;
using EgwCoreLib.Lux.Data.Services.Utils;
using Lux.API.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
@@ -169,86 +155,8 @@ builder.Services.AddDbContextFactory<DataLayerContext>(options =>
.LogTo(_ => { }); // disabilita EF logging;
});
// servizi Scoped (usano DB)
//builder.Services.AddSingleton<DataLayerServices>();
builder.Services.AddScoped<DataLayerServices>();
// Repository con interfaccia
builder.Services.AddScoped<IConfGlassRepository, ConfGlassRepository>();
builder.Services.AddScoped<IConfProfileRepository, ConfProfileRepository>();
builder.Services.AddScoped<IConfWoodRepository, ConfWoodRepository>();
builder.Services.AddScoped<ICostDriverRepository, CostDriverRepository>();
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
builder.Services.AddScoped<IDealerRepository, DealerRepository>();
builder.Services.AddScoped<IEnvirParamRepository, EnvirParamRepository>();
builder.Services.AddScoped<IGenClassRepository, GenClassRepository>();
builder.Services.AddScoped<IGenValRepository, GenValRepository>();
builder.Services.AddScoped<IItemGroupRepository, ItemGroupRepository>();
builder.Services.AddScoped<IItemRepository, ItemRepository>();
builder.Services.AddScoped<IJobStepRepository, JobStepRepository>();
builder.Services.AddScoped<IJobTaskRepository, JobTaskRepository>();
builder.Services.AddScoped<IOfferRepository, OfferRepository>();
builder.Services.AddScoped<IOfferRowRepository, OfferRowRepository>();
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
builder.Services.AddScoped<IOrderRowRepository, OrderRowRepository>();
builder.Services.AddScoped<IProductionBatchRepository, ProductionBatchRepository>();
builder.Services.AddScoped<IProductionGroupRepository, ProductionGroupRepository>();
builder.Services.AddScoped<IProductionItemRepository, ProductionItemRepository>();
builder.Services.AddScoped<IProductionOdlRepository, ProductionOdlRepository>();
builder.Services.AddScoped<IProductionPlantRepository, ProductionPlantRepository>();
builder.Services.AddScoped<IResourceRepository, ResourceRepository>();
builder.Services.AddScoped<ISellingItemRepository, SellingItemRepository>();
builder.Services.AddScoped<ITagRepository, TagRepository>();
builder.Services.AddScoped<ITemplateRepository, TemplateRepository>();
builder.Services.AddScoped<ITemplateRowRepository, TemplateRowRepository>();
// Servizi dati con interfaccia
builder.Services.AddScoped<IConfGlassService, ConfGlassService>();
builder.Services.AddScoped<IConfProfileService, ConfProfileService>();
builder.Services.AddScoped<IConfWoodService, ConfWoodService>();
builder.Services.AddScoped<ICostDriverService, CostDriverService>();
builder.Services.AddScoped<ICustomerService, CustomerService>();
builder.Services.AddScoped<IDealerService, DealerService>();
builder.Services.AddScoped<IEnvirParamService, EnvirParamService>();
builder.Services.AddScoped<IGenClassService, GenClassService>();
builder.Services.AddScoped<IGenValService, GenValService>();
builder.Services.AddScoped<IItemService, ItemService>();
builder.Services.AddScoped<IItemGroupService, ItemGroupService>();
builder.Services.AddScoped<IJobStepService, JobStepService>();
builder.Services.AddScoped<IJobTaskService, JobTaskService>();
builder.Services.AddScoped<IOfferService, OfferService>();
builder.Services.AddScoped<IOfferRowService, OfferRowService>();
builder.Services.AddScoped<IOrderService, OrderService>();
builder.Services.AddScoped<IOrderRowService, OrderRowService>();
builder.Services.AddScoped<IProductionGroupService, ProductionGroupService>();
builder.Services.AddScoped<IProductionItemService, ProductionItemService>();
builder.Services.AddScoped<IProductionBatchService, ProductionBatchService>();
builder.Services.AddScoped<IProductionOdlService, ProductionOdlService>();
builder.Services.AddScoped<IProductionPlantService, ProductionPlantService>();
builder.Services.AddScoped<IResourceService, ResourceService>();
builder.Services.AddScoped<ISellingItemService, SellingItemService>();
builder.Services.AddScoped<ITagService, TagService>();
builder.Services.AddScoped<ITemplateService, TemplateService>();
builder.Services.AddScoped<ITemplateRowService, TemplateRowService>();
// Da rivedere!!!
#if false
// registrazione automatica Repository e Servizi con Scrutor
builder.Services.Scan(scan => scan
.FromAssemblyOf<BaseServ>() // Cerca nell'assembly dove si trova BaseServ
// Registra tutti i Repository
.AddClasses(classes => classes.Where(c => c.Name.EndsWith("Repository")))
.AsImplementedInterfaces() // Es: associa GenClassRepository a IGenClassRepository
.WithScopedLifetime()
// Registra tutti i Servizi
.AddClasses(classes => classes.Where(c => c.Name.EndsWith("Service")))
.AsImplementedInterfaces()
.WithScopedLifetime()
);
#endif
// registrazione in blocco servizi con metodo extension custom
builder.Services.AddLuxData(connectionString);
// servizi Singleton (no DB)
builder.Services.AddSingleton<ImageCacheService>();