Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review lifecycle of services registered in the DI container #459

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Changes from all commits
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
15 changes: 5 additions & 10 deletions Src/Fido2.AspNet/Fido2NetLibBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, ICo

private static void AddServices(this IServiceCollection services)
{
services.AddTransient<IFido2, Fido2>();
services.AddScoped<IFido2, Fido2>();
services.AddSingleton<IMetadataService, NullMetadataService>(); //Default implementation if we choose not to enable MDS
services.TryAddSingleton<ISystemClock, SystemClock>();
}
Expand All @@ -45,14 +45,14 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, Act

public static void AddCachedMetadataService(this IFido2NetLibBuilder builder, Action<IFido2MetadataServiceBuilder> configAction)
{
builder.AddMetadataService<DistributedCacheMetadataService>();
builder.Services.AddScoped<IMetadataService, DistributedCacheMetadataService>();

configAction(new Fido2NetLibBuilder(builder.Services));
}

public static IFido2MetadataServiceBuilder AddFileSystemMetadataRepository(this IFido2MetadataServiceBuilder builder, string directoryPath)
{
builder.Services.AddTransient<IMetadataRepository, FileSystemMetadataRepository>(r =>
builder.Services.AddScoped<IMetadataRepository, FileSystemMetadataRepository>(provider =>
{
return new FileSystemMetadataRepository(directoryPath);
});
Expand All @@ -65,7 +65,7 @@ public static IFido2MetadataServiceBuilder AddConformanceMetadataRepository(
HttpClient client = null,
string origin = "")
{
builder.Services.AddTransient<IMetadataRepository>(provider =>
builder.Services.AddScoped<IMetadataRepository>(provider =>
{
return new ConformanceMetadataRepository(client, origin);
});
Expand All @@ -83,15 +83,10 @@ public static IFido2MetadataServiceBuilder AddFidoMetadataRepository(this IFido2
if (clientBuilder != null)
clientBuilder(httpClientBuilder);

builder.Services.AddTransient<IMetadataRepository, Fido2MetadataServiceRepository>();
builder.Services.AddScoped<IMetadataRepository, Fido2MetadataServiceRepository>();

return builder;
}

private static void AddMetadataService<TService>(this IFido2NetLibBuilder builder) where TService : class, IMetadataService
{
builder.Services.AddScoped<IMetadataService, TService>();
}
}

public interface IFido2NetLibBuilder
Expand Down