Skip to content

Commit

Permalink
Add service lifetime parameter for client-side ICookieService registr…
Browse files Browse the repository at this point in the history
…ation (#10)
  • Loading branch information
YuriyDurov authored Oct 24, 2024
1 parent 8f79428 commit e68cfa4
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ namespace BitzArt.Blazor.Cookies;

public static class AddBlazorCookiesExtension
{
public static WebAssemblyHostBuilder AddBlazorCookies(this WebAssemblyHostBuilder builder)
public static WebAssemblyHostBuilder AddBlazorCookies(this WebAssemblyHostBuilder builder, ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
builder.Services.AddScoped<ICookieService, BrowserCookieService>();
builder.Services.AddBlazorCookiesClient(lifetime);

return builder;
}

private static IServiceCollection AddBlazorCookiesClient(this IServiceCollection services, ServiceLifetime lifetime)
{
services.Add(new ServiceDescriptor(typeof(ICookieService), typeof(BrowserCookieService), lifetime));

return services;
}
}

0 comments on commit e68cfa4

Please sign in to comment.