Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved Lifetime to LibraryConfiguration
  • Loading branch information
svrooij committed Dec 2, 2024
commit 99677b074da78ca93c82e1a0e646aa16228e394d
13 changes: 6 additions & 7 deletions src/Core/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public static class ServiceCollectionExtensions
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">Library configuration</param>
/// <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>
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, LibraryConfiguration? configuration = null, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, LibraryConfiguration? configuration = null)
{
if(serviceLifetime == ServiceLifetime.Transient)
var serviceLifetime = configuration?.ServiceLifetime ?? ServiceLifetime.Scoped;
if (serviceLifetime == ServiceLifetime.Transient)
{
throw new ArgumentException("Transient lifetime is not supported for Fluent UI services.", nameof(serviceLifetime));
throw new NotSupportedException("Transient lifetime is not supported for Fluent UI services.");
}
if (serviceLifetime == ServiceLifetime.Singleton)
{
Expand Down Expand Up @@ -62,12 +62,11 @@ public static IServiceCollection AddFluentUIComponents(this IServiceCollection s
/// </summary>
/// <param name="services">Service collection</param>
/// <param name="configuration">Library configuration</param>
/// <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>
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, Action<LibraryConfiguration> configuration, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
public static IServiceCollection AddFluentUIComponents(this IServiceCollection services, Action<LibraryConfiguration> configuration)
{
LibraryConfiguration options = new();
configuration.Invoke(options);

return AddFluentUIComponents(services, options, serviceLifetime);
return AddFluentUIComponents(services, options);
}
}
7 changes: 7 additions & 0 deletions src/Core/Infrastructure/LibraryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
/// </summary>
public bool HideTooltipOnCursorLeave { get; set; } = false;

/// <summary>
/// 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"/>.
/// Default is <see cref="ServiceLifetime.Scoped"/>.
/// <para>Only <see cref="ServiceLifetime.Scoped"/> and <see cref="ServiceLifetime.Singleton"/> are supported.</para>
/// </summary>
public ServiceLifetime ServiceLifetime { get; set; } = ServiceLifetime.Scoped;

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Test Core Lib

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Demo site

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 42 in src/Core/Infrastructure/LibraryConfiguration.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy Demo site

The type or namespace name 'ServiceLifetime' could not be found (are you missing a using directive or an assembly reference?)

/// <summary>
/// Gets or sets the value indicating whether the library should validate CSS class names.
/// respecting the following regex: "^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$".
Expand Down
Loading