Browse Source

Use a TryAddEnumerable() call per service registration to avoid unnecessary allocations

pull/2160/head
Kévin Chalet 2 years ago
parent
commit
27968f7628
  1. 3
      sandbox/OpenIddict.Sandbox.WinForms.Client/app.manifest
  2. 19
      src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs
  3. 10
      src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs
  4. 10
      src/OpenIddict.Client.Owin/OpenIddictClientOwinExtensions.cs
  5. 17
      src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs
  6. 14
      src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs
  7. 10
      src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs
  8. 10
      src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs
  9. 16
      src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs
  10. 10
      src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs
  11. 10
      src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs
  12. 13
      src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs
  13. 10
      src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs
  14. 6
      src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs
  15. 10
      src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs
  16. 14
      src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs

3
sandbox/OpenIddict.Sandbox.WinForms.Client/app.manifest

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<assemblyIdentity version="1.0.0.0" name="OpenIddict.Sandbox.WinForms.Client.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">

19
src/OpenIddict.Client.AspNetCore/OpenIddictClientAspNetCoreExtensions.cs

@ -48,14 +48,17 @@ public static class OpenIddictClientAspNetCoreExtensions
// Register the option initializer used by the OpenIddict ASP.NET Core client integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>(),
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientAspNetCoreConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictClientAspNetCoreOptions>, OpenIddictClientAspNetCoreConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientAspNetCoreConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictClientAspNetCoreOptions>, OpenIddictClientAspNetCoreConfiguration>());
return new OpenIddictClientAspNetCoreBuilder(builder.Services);
}

10
src/OpenIddict.Client.DataProtection/OpenIddictClientDataProtectionExtensions.cs

@ -40,11 +40,11 @@ public static class OpenIddictClientDataProtectionExtensions
builder.Services.TryAddSingleton<RequireDataProtectionTokenFormat>();
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientDataProtectionConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictClientDataProtectionOptions>, OpenIddictClientDataProtectionConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientDataProtectionConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictClientDataProtectionOptions>, OpenIddictClientDataProtectionConfiguration>());
return new OpenIddictClientDataProtectionBuilder(builder.Services);
}

10
src/OpenIddict.Client.Owin/OpenIddictClientOwinExtensions.cs

@ -49,11 +49,11 @@ public static class OpenIddictClientOwinExtensions
// Register the option initializer used by the OpenIddict OWIN client integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientOwinConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictClientOwinOptions>, OpenIddictClientOwinConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientOwinConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictClientOwinOptions>, OpenIddictClientOwinConfiguration>());
return new OpenIddictClientOwinBuilder(builder.Services);
}

17
src/OpenIddict.Client.SystemIntegration/OpenIddictClientSystemIntegrationExtensions.cs

@ -121,16 +121,17 @@ public static class OpenIddictClientSystemIntegrationExtensions
// Register the option initializer and the background service used by the OpenIddict client system integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers and the background service are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IHostedService, OpenIddictClientSystemIntegrationHttpListener>(),
ServiceDescriptor.Singleton<IHostedService, OpenIddictClientSystemIntegrationPipeListener>(),
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, OpenIddictClientSystemIntegrationHttpListener>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, OpenIddictClientSystemIntegrationPipeListener>());
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemIntegrationConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemIntegrationConfiguration>(),
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemIntegrationConfiguration>());
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictClientSystemIntegrationOptions>, OpenIddictClientSystemIntegrationConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemIntegrationConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictClientSystemIntegrationOptions>, OpenIddictClientSystemIntegrationConfiguration>());
return new OpenIddictClientSystemIntegrationBuilder(builder.Services);
}

14
src/OpenIddict.Client.SystemNetHttp/OpenIddictClientSystemNetHttpExtensions.cs

@ -43,12 +43,14 @@ public static class OpenIddictClientSystemNetHttpExtensions
builder.Services.TryAddSingleton<RequireHttpUri>();
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemNetHttpConfiguration>(),
ServiceDescriptor.Singleton<IConfigureOptions<HttpClientFactoryOptions>, OpenIddictClientSystemNetHttpConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<HttpClientFactoryOptions>, OpenIddictClientSystemNetHttpConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientSystemNetHttpConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<HttpClientFactoryOptions>, OpenIddictClientSystemNetHttpConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<HttpClientFactoryOptions>, OpenIddictClientSystemNetHttpConfiguration>());
return new OpenIddictClientSystemNetHttpBuilder(builder.Services);
}

10
src/OpenIddict.Client.WebIntegration/OpenIddictClientWebIntegrationExtensions.cs

@ -39,11 +39,11 @@ public static partial class OpenIddictClientWebIntegrationExtensions
.Select(descriptor => descriptor.ServiceDescriptor));
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientWebIntegrationConfiguration>(),
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictClientSystemNetHttpOptions>, OpenIddictClientWebIntegrationConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientOptions>, OpenIddictClientWebIntegrationConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictClientSystemNetHttpOptions>, OpenIddictClientWebIntegrationConfiguration>());
// Note: the IPostConfigureOptions<OpenIddictClientOptions> service responsible for populating
// the client registrations MUST be registered before OpenIddictClientConfiguration to ensure

10
src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs

@ -35,11 +35,11 @@ public static class OpenIddictQuartzExtensions
builder.Services.TryAddTransient<OpenIddictQuartzJob>();
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<QuartzOptions>, OpenIddictQuartzConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictQuartzOptions>, OpenIddictQuartzConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<QuartzOptions>, OpenIddictQuartzConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictQuartzOptions>, OpenIddictQuartzConfiguration>());
return new OpenIddictQuartzBuilder(builder.Services);
}

16
src/OpenIddict.Server.AspNetCore/OpenIddictServerAspNetCoreExtensions.cs

@ -52,15 +52,17 @@ public static class OpenIddictServerAspNetCoreExtensions
// Register the option initializer used by the OpenIddict ASP.NET Core server integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<AuthenticationOptions>, OpenIddictServerAspNetCoreConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<AuthenticationOptions>, OpenIddictServerAspNetCoreConfiguration>(),
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<AuthenticationOptions>, OpenIddictServerAspNetCoreConfiguration>());
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerAspNetCoreConfiguration>(),
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<AuthenticationOptions>, OpenIddictServerAspNetCoreConfiguration>());
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictServerAspNetCoreOptions>, OpenIddictServerAspNetCoreConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerAspNetCoreConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictServerAspNetCoreOptions>, OpenIddictServerAspNetCoreConfiguration>());
return new OpenIddictServerAspNetCoreBuilder(builder.Services);
}

10
src/OpenIddict.Server.DataProtection/OpenIddictServerDataProtectionExtensions.cs

@ -40,11 +40,11 @@ public static class OpenIddictServerDataProtectionExtensions
builder.Services.TryAddSingleton<RequireDataProtectionTokenFormat>();
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerDataProtectionConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictServerDataProtectionOptions>, OpenIddictServerDataProtectionConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerDataProtectionConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictServerDataProtectionOptions>, OpenIddictServerDataProtectionConfiguration>());
return new OpenIddictServerDataProtectionBuilder(builder.Services);
}

10
src/OpenIddict.Server.Owin/OpenIddictServerOwinExtensions.cs

@ -54,11 +54,11 @@ public static class OpenIddictServerOwinExtensions
// Register the option initializers used by the OpenIddict OWIN server integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerOwinConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictServerOwinOptions>, OpenIddictServerOwinConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictServerOptions>, OpenIddictServerOwinConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictServerOwinOptions>, OpenIddictServerOwinConfiguration>());
return new OpenIddictServerOwinBuilder(builder.Services);
}

13
src/OpenIddict.Validation.AspNetCore/OpenIddictValidationAspNetCoreExtensions.cs

@ -45,13 +45,14 @@ public static class OpenIddictValidationAspNetCoreExtensions
// Register the option initializer used by the OpenIddict ASP.NET Core validation integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>(),
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>());
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationAspNetCoreConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationAspNetCoreConfiguration>());
return new OpenIddictValidationAspNetCoreBuilder(builder.Services);
}

10
src/OpenIddict.Validation.DataProtection/OpenIddictValidationDataProtectionExtensions.cs

@ -36,11 +36,11 @@ public static class OpenIddictValidationDataProtectionExtensions
builder.Services.TryAdd(OpenIddictValidationDataProtectionHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor));
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationDataProtectionConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictValidationDataProtectionOptions>, OpenIddictValidationDataProtectionConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationDataProtectionConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictValidationDataProtectionOptions>, OpenIddictValidationDataProtectionConfiguration>());
return new OpenIddictValidationDataProtectionBuilder(builder.Services);
}

6
src/OpenIddict.Validation.Owin/OpenIddictValidationOwinExtensions.cs

@ -46,10 +46,8 @@ public static class OpenIddictValidationOwinExtensions
// Register the option initializers used by the OpenIddict OWIN validation integration services.
// Note: TryAddEnumerable() is used here to ensure the initializers are only registered once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationOwinConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationOwinConfiguration>());
return new OpenIddictValidationOwinBuilder(builder.Services);
}

10
src/OpenIddict.Validation.ServerIntegration/OpenIddictValidationServerIntegrationExtensions.cs

@ -31,11 +31,11 @@ public static class OpenIddictValidationServerIntegrationExtensions
}
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>());
return new OpenIddictValidationServerIntegrationBuilder(builder.Services);
}

14
src/OpenIddict.Validation.SystemNetHttp/OpenIddictValidationSystemNetHttpExtensions.cs

@ -43,12 +43,14 @@ public static class OpenIddictValidationSystemNetHttpExtensions
builder.Services.TryAddSingleton<RequireHttpUri>();
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(
[
ServiceDescriptor.Singleton<IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationSystemNetHttpConfiguration>(),
ServiceDescriptor.Singleton<IConfigureOptions<HttpClientFactoryOptions>, OpenIddictValidationSystemNetHttpConfiguration>(),
ServiceDescriptor.Singleton<IPostConfigureOptions<HttpClientFactoryOptions>, OpenIddictValidationSystemNetHttpConfiguration>()
]);
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<OpenIddictValidationOptions>, OpenIddictValidationSystemNetHttpConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IConfigureOptions<HttpClientFactoryOptions>, OpenIddictValidationSystemNetHttpConfiguration>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<
IPostConfigureOptions<HttpClientFactoryOptions>, OpenIddictValidationSystemNetHttpConfiguration>());
return new OpenIddictValidationSystemNetHttpBuilder(builder.Services);
}

Loading…
Cancel
Save