Files
SteUP_Dotnet/SteUp.Maui/Core/CoreModule.cs
2026-03-02 10:50:34 +01:00

79 lines
3.0 KiB
C#

using CommunityToolkit.Mvvm.Messaging;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.EntityFrameworkCore;
using SteUp.Data.LocalDb;
using SteUp.Data.LocalDb.EntityServices;
using SteUp.Maui.Core.Services;
using SteUp.Maui.Core.System;
using SteUp.Maui.Core.System.Network;
using SteUp.Shared.Core.BarcodeReader;
using SteUp.Shared.Core.BarcodeReader.Contracts;
using SteUp.Shared.Core.Data;
using SteUp.Shared.Core.Data.Contracts;
using SteUp.Shared.Core.Interface;
using SteUp.Shared.Core.Interface.IntegryApi;
using SteUp.Shared.Core.Interface.LocalDb;
using SteUp.Shared.Core.Interface.System;
using SteUp.Shared.Core.Interface.System.Network;
using SteUp.Shared.Core.Messages.Ispezione;
using SteUp.Shared.Core.Messages.Scanner;
using SteUp.Shared.Core.Messages.Scheda;
using SteUp.Shared.Core.Services;
namespace SteUp.Maui.Core;
public static class CoreModule
{
extension(MauiAppBuilder builder)
{
public void RegisterAppServices()
{
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddScoped<ISteupDataService, SteupDataService>();
builder.Services.AddSingleton<IBarcodeManager, BarcodeManager>();
}
public void RegisterIntegryServices()
{
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<IIntegrySteupService, IntegrySteupService>();
}
public void RegisterSystemService()
{
builder.Services.AddSingleton<INetworkService, NetworkService>();
builder.Services.AddSingleton<IAttachedService, AttachedService>();
builder.Services.AddSingleton<IBarcodeReaderService, HoneywellScannerService>();
}
public void AddAuthorizationCore()
{
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AppAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
}
public void RegisterMessageServices()
{
builder.Services.AddSingleton<IMessenger, WeakReferenceMessenger>();
builder.Services.AddSingleton<NewSchedaService>();
builder.Services.AddSingleton<OnScannerService>();
builder.Services.AddSingleton<CompleteInspectionService>();
}
public void RegisterDbServices()
{
builder.Services.AddSingleton<IDbPathProvider, DbPathProvider>();
builder.Services.AddDbContext<AppDbContext>((sp, options) =>
{
var dbPath = sp.GetRequiredService<IDbPathProvider>().GetDbPath();
options.UseSqlite($"Filename={dbPath}");
});
builder.Services.AddSingleton<IDbInitializer, DbInitializer>();
builder.Services.AddSingleton<IIspezioniService, IspezioniService>();
}
}
}