Skip to content

Commit cc0e169

Browse files
committed
Moved Lifetime to LibraryConfiguration
1 parent 6346380 commit cc0e169

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Core/Extensions/ServiceCollectionExtensions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ public static class ServiceCollectionExtensions
1212
/// </summary>
1313
/// <param name="services">Service collection</param>
1414
/// <param name="configuration">Library configuration</param>
15-
/// <param name="serviceLifetime">In case you want to use any of the services outside of the request, you can change the lifetime to <see cref="ServiceLifetime.Singleton"/>. Normally all services are registered as <see cref="ServiceLifetime.Scoped"/>.</param>
16-
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, LibraryConfiguration? configuration = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
15+
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, LibraryConfiguration? configuration = null)
1716
{
18-
if(serviceLifetime == ServiceLifetime.Transient)
17+
var serviceLifetime = configuration?.ServiceLifetime ?? ServiceLifetime.Scoped;
18+
if (serviceLifetime == ServiceLifetime.Transient)
1919
{
20-
throw new ArgumentException("Transient lifetime is not supported for Fluent UI services.", nameof(serviceLifetime));
20+
throw new NotSupportedException("Transient lifetime is not supported for Fluent UI services.");
2121
}
2222
if (serviceLifetime == ServiceLifetime.Singleton)
2323
{
@@ -62,12 +62,11 @@ public static IServiceCollection AddFluentUIComponents(this IServiceCollection s
6262
/// </summary>
6363
/// <param name="services">Service collection</param>
6464
/// <param name="configuration">Library configuration</param>
65-
/// <param name="serviceLifetime">In case you want to use any of the services outside of the request, you can change the lifetime to <see cref="ServiceLifetime.Singleton"/>. Normally all services are registered as <see cref="ServiceLifetime.Scoped"/>.</param>
66-
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, Action<LibraryConfiguration> configuration, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
65+
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, Action<LibraryConfiguration> configuration)
6766
{
6867
LibraryConfiguration options = new();
6968
configuration.Invoke(options);
7069

71-
return AddFluentUIComponents(services, options, serviceLifetime);
70+
return AddFluentUIComponents(services, options);
7271
}
7372
}

src/Core/Infrastructure/LibraryConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public class LibraryConfiguration
3434
/// </summary>
3535
public bool HideTooltipOnCursorLeave { get; set; } = false;
3636

37+
/// <summary>
38+
/// Gets or sets the service lifetime for the library services, when using Fluent UI in WebAssembly, it can make sense to use <see cref="ServiceLifetime.Singleton"/>.
39+
/// Default is <see cref="ServiceLifetime.Scoped"/>.
40+
/// <para>Only <see cref="ServiceLifetime.Scoped"/> and <see cref="ServiceLifetime.Singleton"/> are supported.</para>
41+
/// </summary>
42+
public ServiceLifetime ServiceLifetime { get; set; } = ServiceLifetime.Scoped;
43+
3744
/// <summary>
3845
/// Gets or sets the value indicating whether the library should validate CSS class names.
3946
/// respecting the following regex: "^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$".

0 commit comments

Comments
 (0)