/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using OpenIddict.Validation;
using OpenIddict.Validation.ServerIntegration;
namespace Microsoft.Extensions.DependencyInjection
{
///
/// Exposes extensions allowing to register the OpenIddict validation/server integration services.
///
public static class OpenIddictValidationServerIntegrationExtensions
{
///
/// Registers the OpenIddict validation/server integration services in the DI container
/// and automatically imports the configuration from the local OpenIddict server.
///
/// The services builder used by OpenIddict to register new services.
/// This extension can be safely called multiple times.
/// The .
public static OpenIddictValidationServerIntegrationBuilder UseLocalServer(this OpenIddictValidationBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
// Note: TryAddEnumerable() is used here to ensure the initializers are registered only once.
builder.Services.TryAddEnumerable(new[]
{
ServiceDescriptor.Singleton, OpenIddictValidationServerIntegrationConfiguration>(),
ServiceDescriptor.Singleton, OpenIddictValidationServerIntegrationConfiguration>()
});
return new OpenIddictValidationServerIntegrationBuilder(builder.Services);
}
///
/// Registers the OpenIddict validation/server integration services in the DI container
/// and automatically imports the configuration from the local OpenIddict server.
///
/// The services builder used by OpenIddict to register new services.
/// The configuration delegate used to configure the validation services.
/// This extension can be safely called multiple times.
/// The .
public static OpenIddictValidationBuilder UseLocalServer(
this OpenIddictValidationBuilder builder, Action configuration)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
configuration(builder.UseLocalServer());
return builder;
}
}
}