/* * 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.Diagnostics.CodeAnalysis; using Microsoft.Extensions.DependencyInjection; using OpenIddict.EntityFramework; using OpenIddict.EntityFramework.Models; namespace System.Data.Entity; /// /// Exposes extensions simplifying the integration between OpenIddict and Entity Framework 6.x. /// public static class OpenIddictEntityFrameworkHelpers { /// /// Registers the OpenIddict entity sets in the Entity Framework 6.x context /// using the default OpenIddict models and the default key type (string). /// /// The builder used to configure the Entity Framework context. /// The Entity Framework context builder. public static DbModelBuilder UseOpenIddict(this DbModelBuilder builder) => builder.UseOpenIddict(); /// /// Registers the OpenIddict entity sets in the Entity Framework 6.x /// context using the specified entities and the specified key type. /// /// /// Note: when using custom entities, the new entities MUST be registered by calling /// . /// /// The builder used to configure the Entity Framework context. /// The Entity Framework context builder. public static DbModelBuilder UseOpenIddict< [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TApplication, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TAuthorization, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResource, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TScope, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TSession, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TToken, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TKey>(this DbModelBuilder builder) where TApplication : OpenIddictEntityFrameworkApplication where TAuthorization : OpenIddictEntityFrameworkAuthorization where TResource : OpenIddictEntityFrameworkResource where TScope : OpenIddictEntityFrameworkScope where TSession : OpenIddictEntityFrameworkSession where TToken : OpenIddictEntityFrameworkToken where TKey : notnull, IEquatable { ArgumentNullException.ThrowIfNull(builder); builder.Configurations .Add(new OpenIddictEntityFrameworkApplicationConfiguration()) .Add(new OpenIddictEntityFrameworkAuthorizationConfiguration()) .Add(new OpenIddictEntityFrameworkResourceConfiguration()) .Add(new OpenIddictEntityFrameworkScopeConfiguration()) .Add(new OpenIddictEntityFrameworkSessionConfiguration()) .Add(new OpenIddictEntityFrameworkTokenConfiguration()); return builder; } }