From 90754c03de57e2fc13c8745051adbc2c647d899d Mon Sep 17 00:00:00 2001 From: Saleh Yusefnejad Date: Mon, 2 Dec 2024 20:26:32 +0330 Subject: [PATCH] feat(blazorui): remove singleton option from BlazorUI service registration #9379 (#9380) --- .../IServiceCollectionExtensions.cs | 10 ++++++++-- .../IServiceCollectionExtensions.cs | 11 ++--------- .../Extensions/IServiceCollectionExtensions.cs | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) rename src/BlazorUI/Bit.BlazorUI/{Utils => Extensions}/IServiceCollectionExtensions.cs (54%) diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/IServiceCollectionExtensions.cs b/src/BlazorUI/Bit.BlazorUI.Extras/IServiceCollectionExtensions.cs index 2a476d7020..108d64b637 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/IServiceCollectionExtensions.cs +++ b/src/BlazorUI/Bit.BlazorUI.Extras/IServiceCollectionExtensions.cs @@ -5,9 +5,15 @@ namespace Bit.BlazorUI; public static class IServiceCollectionExtensions { - public static IServiceCollection AddBitBlazorUIExtrasServices(this IServiceCollection services, bool singleton = false) + /// + /// Registers required services of the Extras package of the BitBlazorUI components. + /// + /// + /// Tries to register the services as singleton, but only for the services can be singleton (e.g. the services that do not use IJSRuntime). + /// + public static IServiceCollection AddBitBlazorUIExtrasServices(this IServiceCollection services, bool trySingleton = false) { - if (singleton) + if (trySingleton) { services.TryAddSingleton(); } diff --git a/src/BlazorUI/Bit.BlazorUI/Utils/IServiceCollectionExtensions.cs b/src/BlazorUI/Bit.BlazorUI/Extensions/IServiceCollectionExtensions.cs similarity index 54% rename from src/BlazorUI/Bit.BlazorUI/Utils/IServiceCollectionExtensions.cs rename to src/BlazorUI/Bit.BlazorUI/Extensions/IServiceCollectionExtensions.cs index 02ddf71eb9..c2eade972f 100644 --- a/src/BlazorUI/Bit.BlazorUI/Utils/IServiceCollectionExtensions.cs +++ b/src/BlazorUI/Bit.BlazorUI/Extensions/IServiceCollectionExtensions.cs @@ -5,16 +5,9 @@ namespace Bit.BlazorUI; public static class IServiceCollectionExtensions { - public static IServiceCollection AddBitBlazorUIServices(this IServiceCollection services, bool singleton = false) + public static IServiceCollection AddBitBlazorUIServices(this IServiceCollection services) { - if (singleton) - { - services.TryAddSingleton(); - } - else - { - services.TryAddScoped(); - } + services.TryAddScoped(); return services; } diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Extensions/IServiceCollectionExtensions.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Extensions/IServiceCollectionExtensions.cs index 2f3c89c0ec..e0e28c4ada 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Extensions/IServiceCollectionExtensions.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Extensions/IServiceCollectionExtensions.cs @@ -23,8 +23,8 @@ public static IServiceCollection AddClientSharedServices(this IServiceCollection services.TryAddTransient(); services.TryAddScoped(); - services.AddBitBlazorUIServices(singleton: AppRenderMode.IsBlazorHybrid); - services.AddBitBlazorUIExtrasServices(singleton: AppRenderMode.IsBlazorHybrid); + services.AddBitBlazorUIServices(); + services.AddBitBlazorUIExtrasServices(trySingleton: AppRenderMode.IsBlazorHybrid); services.AddSharedServices(); return services;