From 2d4dde22906253b501278a9badfbed59d77c0283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Thu, 22 Dec 2016 15:55:52 +0100 Subject: [PATCH] Introduce new services.AddOpenIddict() overloads to allow delegate-based configuration --- src/OpenIddict.Core/OpenIddictExtensions.cs | 78 ++++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/src/OpenIddict.Core/OpenIddictExtensions.cs b/src/OpenIddict.Core/OpenIddictExtensions.cs index 7e127de5..70c9b6e4 100644 --- a/src/OpenIddict.Core/OpenIddictExtensions.cs +++ b/src/OpenIddict.Core/OpenIddictExtensions.cs @@ -19,11 +19,10 @@ namespace Microsoft.Extensions.DependencyInjection { /// The services collection. /// The . public static OpenIddictBuilder AddOpenIddict([NotNull] this IServiceCollection services) { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } - - return services.AddOpenIddict(); + return services.AddOpenIddict(); } /// @@ -35,10 +34,6 @@ namespace Microsoft.Extensions.DependencyInjection { /// The . public static OpenIddictBuilder AddOpenIddict([NotNull] this IServiceCollection services) where TKey : IEquatable { - if (services == null) { - throw new ArgumentNullException(nameof(services)); - } - return services.AddOpenIddict, OpenIddictAuthorization, OpenIddictScope, @@ -81,5 +76,70 @@ namespace Microsoft.Extensions.DependencyInjection { return builder; } + + /// + /// Registers the default OpenIddict services in the DI container, + /// using the default entities and the default entity key type. + /// + /// The services collection. + /// The configuration delegate used to register new services. + /// The . + public static IServiceCollection AddOpenIddict( + [NotNull] this IServiceCollection services, + [NotNull] Action configuration) { + return services.AddOpenIddict(configuration); + } + + /// + /// Registers the default OpenIddict services in the DI container, + /// using the default entities and the specified entity key type. + /// + /// The type of the entity primary keys. + /// The services collection. + /// The configuration delegate used to register new services. + /// The . + public static IServiceCollection AddOpenIddict( + [NotNull] this IServiceCollection services, + [NotNull] Action configuration) + where TKey : IEquatable { + return services.AddOpenIddict, + OpenIddictAuthorization, + OpenIddictScope, + OpenIddictToken>(configuration); + } + + /// + /// Registers the default OpenIddict services in the DI container, using the specified entities. + /// + /// The type of the Application entity. + /// The type of the Authorization entity. + /// The type of the Scope entity. + /// The type of the Token entity. + /// The services collection. + /// The configuration delegate used to register new services. + /// The . + public static IServiceCollection AddOpenIddict( + [NotNull] this IServiceCollection services, + [NotNull] Action configuration) + where TApplication : class + where TAuthorization : class + where TScope : class + where TToken : class { + if (services == null) { + throw new ArgumentNullException(nameof(services)); + } + + if (configuration == null) { + throw new ArgumentNullException(nameof(configuration)); + } + + // Register the OpenIddict core services and invoke the configuration delegate. + configuration(services.AddOpenIddict()); + + return services; + } } } \ No newline at end of file