Files
SteUP_Dotnet/SteUp.Maui/Core/CoreModule.cs

60 lines
2.2 KiB
C#

using System.Data;
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.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.Services;
namespace SteUp.Maui.Core;
public static class CoreModule
{
public static void RegisterAppServices(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IFormFactor, FormFactor>();
builder.Services.AddSingleton<IGenericSystemService, GenericSystemService>();
builder.Services.AddScoped<ISteupDataService, SteupDataService>();
}
public static void RegisterIntegryServices(this MauiAppBuilder builder)
{
builder.Services.AddScoped<IIntegryApiService, IntegryApiService>();
builder.Services.AddScoped<IIntegrySteupService, IntegrySteupService>();
}
public static void RegisterSystemService(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<INetworkService, NetworkService>();
}
public static void AddAuthorizationCore(this MauiAppBuilder builder)
{
builder.Services.AddAuthorizationCore();
builder.Services.AddScoped<AppAuthenticationStateProvider>();
builder.Services.AddScoped<AuthenticationStateProvider>(provider =>
provider.GetRequiredService<AppAuthenticationStateProvider>());
}
public static void RegisterDbServices(this MauiAppBuilder builder)
{
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>();
}
}