using Daybreak.API.Services.Interop; using Daybreak.Shared.Services.BuildTemplates; using Daybreak.Shared.Services.MDns; using System.Diagnostics.CodeAnalysis; namespace Daybreak.API.Services; public static class WebApplicationBuilderExtensions { public static WebApplicationBuilder WithDaybreakServices(this WebApplicationBuilder builder) { builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.WithHookHostedService(); builder.WithHookHostedService(); builder.WithAddressService(); builder.WithAddressService(); builder.WithAddressService(); builder.WithAddressService(); builder.WithAddressService(); builder.WithAddressService(); builder.WithHookAddressHostedService(); return builder; } private static WebApplicationBuilder WithHookService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IHookHealthService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } private static WebApplicationBuilder WithAddressService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IAddressHealthService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } private static WebApplicationBuilder WithHookHostedService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IHookHealthService, IHostedService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } private static WebApplicationBuilder WithAddressHostedService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IAddressHealthService, IHostedService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } private static WebApplicationBuilder WithHookAddressService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IHookHealthService, IAddressHealthService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } private static WebApplicationBuilder WithHookAddressHostedService<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(this WebApplicationBuilder builder) where T : class, IHookHealthService, IAddressHealthService, IHostedService { builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService()); builder.Services.AddSingleton(sp => sp.GetRequiredService()); return builder; } }