From b348a12a1c88568fa6ea5ba195e95effedb3cf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Mon, 11 Jun 2018 15:27:44 +0200 Subject: [PATCH] Update the EF 6.x/EF Core entities to use HashSet instead of List and automatically register EF 6.x context classes in the DI container --- .../OpenIddictApplication.cs | 4 ++-- .../OpenIddictAuthorization.cs | 2 +- .../OpenIddictEntityFrameworkBuilder.cs | 3 +++ .../OpenIddictApplication.cs | 4 ++-- .../OpenIddictAuthorization.cs | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs b/src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs index 2134d879..e60df750 100644 --- a/src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs +++ b/src/OpenIddict.EntityFramework.Models/OpenIddictApplication.cs @@ -29,7 +29,7 @@ namespace OpenIddict.EntityFramework.Models /// /// Gets the list of the authorizations associated with this application. /// - public virtual IList Authorizations { get; } = new List(); + public virtual ICollection Authorizations { get; } = new HashSet(); /// /// Gets or sets the client identifier @@ -94,7 +94,7 @@ namespace OpenIddict.EntityFramework.Models /// /// Gets the list of the tokens associated with this application. /// - public virtual IList Tokens { get; } = new List(); + public virtual ICollection Tokens { get; } = new HashSet(); /// /// Gets or sets the application type diff --git a/src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs b/src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs index 2343329a..7ebfd69d 100644 --- a/src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs +++ b/src/OpenIddict.EntityFramework.Models/OpenIddictAuthorization.cs @@ -67,7 +67,7 @@ namespace OpenIddict.EntityFramework.Models /// /// Gets the list of tokens associated with the current authorization. /// - public virtual IList Tokens { get; } = new List(); + public virtual ICollection Tokens { get; } = new HashSet(); /// /// Gets or sets the type of the current authorization. diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs index 202a2a2c..c3a99690 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs @@ -8,6 +8,7 @@ using System; using System.ComponentModel; using System.Data.Entity; using JetBrains.Annotations; +using Microsoft.Extensions.DependencyInjection.Extensions; using OpenIddict.Core; using OpenIddict.EntityFramework; using OpenIddict.EntityFramework.Models; @@ -82,6 +83,8 @@ namespace Microsoft.Extensions.DependencyInjection throw new ArgumentException("The specified type is invalid.", nameof(type)); } + Services.TryAddScoped(type); + return Configure(options => options.DbContextType = type); } diff --git a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs index 9b11b33b..e5306535 100644 --- a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs +++ b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictApplication.cs @@ -36,7 +36,7 @@ namespace OpenIddict.EntityFrameworkCore.Models /// /// Gets the list of the authorizations associated with this application. /// - public virtual IList Authorizations { get; } = new List(); + public virtual ICollection Authorizations { get; } = new HashSet(); /// /// Gets or sets the client identifier @@ -101,7 +101,7 @@ namespace OpenIddict.EntityFrameworkCore.Models /// /// Gets the list of the tokens associated with this application. /// - public virtual IList Tokens { get; } = new List(); + public virtual ICollection Tokens { get; } = new HashSet(); /// /// Gets or sets the application type diff --git a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs index 608080b6..67cc0272 100644 --- a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs +++ b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictAuthorization.cs @@ -74,7 +74,7 @@ namespace OpenIddict.EntityFrameworkCore.Models /// /// Gets the list of tokens associated with the current authorization. /// - public virtual IList Tokens { get; } = new List(); + public virtual ICollection Tokens { get; } = new HashSet(); /// /// Gets or sets the type of the current authorization.