Browse Source

Move the entities validation logic from the configuration classes to the EF 6.x builder class

pull/912/head
Kévin Chalet 6 years ago
parent
commit
3fc9a06e8b
  1. 12
      src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs
  2. 12
      src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs
  3. 12
      src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs
  4. 12
      src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs
  5. 14
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs

12
src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs

@ -9,7 +9,6 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Text;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework
@ -30,17 +29,6 @@ namespace OpenIddict.EntityFramework
{
public OpenIddictApplicationConfiguration()
{
// Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x
// always throws an exception when using generic types as entity types.
// To ensure a better exception is thrown, a manual check is made here.
if (typeof(TApplication).IsGenericType)
{
throw new InvalidOperationException(new StringBuilder()
.AppendLine("The application entity cannot be a generic type.")
.Append("Consider creating a non-generic derived class.")
.ToString());
}
// Warning: optional foreign keys MUST NOT be added as CLR properties because
// Entity Framework would throw an exception due to the TKey generic parameter
// being non-nullable when using value types like short, int, long or Guid.

12
src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs

@ -7,7 +7,6 @@
using System;
using System.ComponentModel;
using System.Data.Entity.ModelConfiguration;
using System.Text;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework
@ -28,17 +27,6 @@ namespace OpenIddict.EntityFramework
{
public OpenIddictAuthorizationConfiguration()
{
// Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x
// always throws an exception when using generic types as entity types.
// To ensure a better exception is thrown, a manual check is made here.
if (typeof(TAuthorization).IsGenericType)
{
throw new InvalidOperationException(new StringBuilder()
.AppendLine("The authorization entity cannot be a generic type.")
.Append("Consider creating a non-generic derived class.")
.ToString());
}
// Warning: optional foreign keys MUST NOT be added as CLR properties because
// Entity Framework would throw an exception due to the TKey generic parameter
// being non-nullable when using value types like short, int, long or Guid.

12
src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs

@ -9,7 +9,6 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Text;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework
@ -26,17 +25,6 @@ namespace OpenIddict.EntityFramework
{
public OpenIddictScopeConfiguration()
{
// Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x
// always throws an exception when using generic types as entity types.
// To ensure a better exception is thrown, a manual check is made here.
if (typeof(TScope).IsGenericType)
{
throw new InvalidOperationException(new StringBuilder()
.AppendLine("The scope entity cannot be a generic type.")
.Append("Consider creating a non-generic derived class.")
.ToString());
}
// Warning: optional foreign keys MUST NOT be added as CLR properties because
// Entity Framework would throw an exception due to the TKey generic parameter
// being non-nullable when using value types like short, int, long or Guid.

12
src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs

@ -9,7 +9,6 @@ using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Text;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework
@ -30,17 +29,6 @@ namespace OpenIddict.EntityFramework
{
public OpenIddictTokenConfiguration()
{
// Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x
// always throws an exception when using generic types as entity types.
// To ensure a better exception is thrown, a manual check is made here.
if (typeof(TToken).IsGenericType)
{
throw new InvalidOperationException(new StringBuilder()
.AppendLine("The token entity cannot be a generic type.")
.Append("Consider creating a non-generic derived class.")
.ToString());
}
// Warning: optional foreign keys MUST NOT be added as CLR properties because
// Entity Framework would throw an exception due to the TKey generic parameter
// being non-nullable when using value types like short, int, long or Guid.

14
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs

@ -7,6 +7,7 @@
using System;
using System.ComponentModel;
using System.Data.Entity;
using System.Text;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OpenIddict.Core;
@ -63,6 +64,19 @@ namespace Microsoft.Extensions.DependencyInjection
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization>
where TKey : IEquatable<TKey>
{
// Note: unlike Entity Framework Core 1.x/2.x/3.x, Entity Framework 6.x
// always throws an exception when using generic types as entity types.
// To ensure a better exception is thrown, a manual check is made here.
if (typeof(TApplication).IsGenericType || typeof(TAuthorization).IsGenericType ||
typeof(TScope).IsGenericType || typeof(TToken).IsGenericType)
{
throw new InvalidOperationException(new StringBuilder()
.AppendLine("The Entity Framework 6.x stores cannot be used with generic types.")
.Append("Consider creating non-generic classes derived from the default entities ")
.Append("for the application, authorization, scope and token entities.")
.ToString());
}
Services.Configure<OpenIddictCoreOptions>(options =>
{
options.DefaultApplicationType = typeof(TApplication);

Loading…
Cancel
Save