Browse Source

Move the distributed/memory cache services registration from OpenIddict.Core to the stores/server packages

pull/644/head
Kévin Chalet 8 years ago
parent
commit
0cf7311664
  1. 2
      src/OpenIddict.Core/OpenIddict.Core.csproj
  2. 2
      src/OpenIddict.Core/OpenIddictCoreExtensions.cs
  3. 1
      src/OpenIddict.EntityFramework/OpenIddict.EntityFramework.csproj
  4. 2
      src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs
  5. 1
      src/OpenIddict.EntityFrameworkCore/OpenIddict.EntityFrameworkCore.csproj
  6. 2
      src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs
  7. 8
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs
  8. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs
  9. 8
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs
  10. 10
      src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs
  11. 1
      src/OpenIddict.MongoDb/OpenIddict.MongoDb.csproj
  12. 2
      src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs
  13. 3
      src/OpenIddict.Server/OpenIddictServerExtensions.cs
  14. 1
      src/OpenIddict.Validation/OpenIddictValidationExtensions.cs

2
src/OpenIddict.Core/OpenIddict.Core.csproj

@ -19,8 +19,8 @@
<ItemGroup>
<PackageReference Include="CryptoHelper" Version="$(CryptoHelperVersion)" />
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

2
src/OpenIddict.Core/OpenIddictCoreExtensions.cs

@ -29,8 +29,6 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddDistributedMemoryCache();
builder.Services.AddMemoryCache();
builder.Services.AddOptions();
builder.Services.TryAddScoped(typeof(OpenIddictApplicationManager<>));

1
src/OpenIddict.EntityFramework/OpenIddict.EntityFramework.csproj

@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="EntityFramework" Version="$(EntityFrameworkVersion)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" />
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
</ItemGroup>

2
src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkExtensions.cs

@ -32,6 +32,8 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddMemoryCache();
builder.SetDefaultApplicationEntity<OpenIddictApplication>()
.SetDefaultAuthorizationEntity<OpenIddictAuthorization>()
.SetDefaultScopeEntity<OpenIddictScope>()

1
src/OpenIddict.EntityFrameworkCore/OpenIddict.EntityFrameworkCore.csproj

@ -20,6 +20,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" />
</ItemGroup>
</Project>

2
src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreExtensions.cs

@ -30,6 +30,8 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddMemoryCache();
builder.SetDefaultApplicationEntity<OpenIddictApplication>()
.SetDefaultAuthorizationEntity<OpenIddictAuthorization>()
.SetDefaultScopeEntity<OpenIddictScope>()

8
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictApplicationStore.cs

@ -276,7 +276,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve an application using its client identifier.
/// </summary>
private static Func<TContext, string, Task<TApplication>> FindByClientId =
private static readonly Func<TContext, string, Task<TApplication>> FindByClientId =
EF.CompileAsyncQuery((TContext context, string identifier) =>
(from application in context.Set<TApplication>().AsTracking()
where application.ClientId == identifier
@ -304,7 +304,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve an application using its unique identifier.
/// </summary>
private static Func<TContext, TKey, Task<TApplication>> FindById =
private static readonly Func<TContext, TKey, Task<TApplication>> FindById =
EF.CompileAsyncQuery((TContext context, TKey identifier) =>
(from application in context.Set<TApplication>().AsTracking()
where application.Id.Equals(identifier)
@ -333,7 +333,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve all the applications
/// associated with the specified post_logout_redirect_uri.
/// </summary>
private static Func<TContext, string, AsyncEnumerable<TApplication>> FindByPostLogoutRedirectUri =
private static readonly Func<TContext, string, AsyncEnumerable<TApplication>> FindByPostLogoutRedirectUri =
// To optimize the efficiency of the query a bit, only applications whose stringified
// PostLogoutRedirectUris contains the specified URL are returned. Once the applications
// are retrieved, a second pass is made to ensure only valid elements are returned.
@ -385,7 +385,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve all the
/// applications associated with the specified redirect_uri.
/// </summary>
private static Func<TContext, string, AsyncEnumerable<TApplication>> FindByRedirectUri =
private static readonly Func<TContext, string, AsyncEnumerable<TApplication>> FindByRedirectUri =
// To optimize the efficiency of the query a bit, only applications whose stringified
// RedirectUris property contains the specified URL are returned. Once the applications
// are retrieved, a second pass is made to ensure only valid elements are returned.

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictAuthorizationStore.cs

@ -253,7 +253,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve the authorizations corresponding
/// to the specified subject and associated with the application identifier.
/// </summary>
private static Func<TContext, TKey, string, AsyncEnumerable<TAuthorization>> FindBySubjectAndClient =
private static readonly Func<TContext, TKey, string, AsyncEnumerable<TAuthorization>> FindBySubjectAndClient =
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using authorization.Application.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
@ -298,7 +298,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve the authorizations matching the specified parameters.
/// </summary>
private static Func<TContext, TKey, string, string, AsyncEnumerable<TAuthorization>> FindBySubjectClientAndStatus =
private static readonly Func<TContext, TKey, string, string, AsyncEnumerable<TAuthorization>> FindBySubjectClientAndStatus =
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using authorization.Application.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
@ -349,7 +349,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve the authorizations matching the specified parameters.
/// </summary>
private static Func<TContext, TKey, string, string, string, AsyncEnumerable<TAuthorization>> FindBySubjectClientStatusAndType =
private static readonly Func<TContext, TKey, string, string, string, AsyncEnumerable<TAuthorization>> FindBySubjectClientStatusAndType =
// Note: due to a bug in Entity Framework Core's query visitor, the authorizations can't be
// filtered using authorization.Application.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
@ -408,7 +408,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve an authorization using its unique identifier.
/// </summary>
private static Func<TContext, TKey, Task<TAuthorization>> FindById =
private static readonly Func<TContext, TKey, Task<TAuthorization>> FindById =
EF.CompileAsyncQuery((TContext context, TKey identifier) =>
(from authorization in context.Set<TAuthorization>()
.Include(authorization => authorization.Application)
@ -439,7 +439,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve all the
/// authorizations corresponding to the specified subject.
/// </summary>
private static Func<TContext, string, AsyncEnumerable<TAuthorization>> FindBySubject =
private static readonly Func<TContext, string, AsyncEnumerable<TAuthorization>> FindBySubject =
EF.CompileAsyncQuery((TContext context, string subject) =>
from authorization in context.Set<TAuthorization>()
.Include(authorization => authorization.Application)

8
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictScopeStore.cs

@ -183,7 +183,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve a scope using its unique identifier.
/// </summary>
private static Func<TContext, TKey, Task<TScope>> FindById =
private static readonly Func<TContext, TKey, Task<TScope>> FindById =
EF.CompileAsyncQuery((TContext context, TKey identifier) =>
(from scope in context.Set<TScope>().AsTracking()
where scope.Id.Equals(identifier)
@ -211,7 +211,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve a scope using its name.
/// </summary>
private static Func<TContext, string, Task<TScope>> FindByName =
private static readonly Func<TContext, string, Task<TScope>> FindByName =
EF.CompileAsyncQuery((TContext context, string name) =>
(from scope in context.Set<TScope>().AsTracking()
where scope.Name == name
@ -239,7 +239,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve a list of scopes using their name.
/// </summary>
private static Func<TContext, ImmutableArray<string>, AsyncEnumerable<TScope>> FindByNames =
private static readonly Func<TContext, ImmutableArray<string>, AsyncEnumerable<TScope>> FindByNames =
EF.CompileAsyncQuery((TContext context, ImmutableArray<string> names) =>
from scope in context.Set<TScope>().AsTracking()
where names.Contains(scope.Name)
@ -268,7 +268,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve all the scopes that contain the specified resource.
/// </summary>
private static Func<TContext, string, AsyncEnumerable<TScope>> FindByResource =
private static readonly Func<TContext, string, AsyncEnumerable<TScope>> FindByResource =
// To optimize the efficiency of the query a bit, only scopes whose stringified
// Resources column contains the specified resource are returned. Once the scopes
// are retrieved, a second pass is made to ensure only valid elements are returned.

10
src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictTokenStore.cs

@ -206,7 +206,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve the list of
/// tokens corresponding to the specified application identifier.
/// </summary>
private static Func<TContext, TKey, AsyncEnumerable<TToken>> FindByApplicationId =
private static readonly Func<TContext, TKey, AsyncEnumerable<TToken>> FindByApplicationId =
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
// filtered using token.Application.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
@ -244,7 +244,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve the list of
/// tokens corresponding to the specified authorization identifier.
/// </summary>
private static Func<TContext, TKey, AsyncEnumerable<TToken>> FindByAuthorizationId =
private static readonly Func<TContext, TKey, AsyncEnumerable<TToken>> FindByAuthorizationId =
// Note: due to a bug in Entity Framework Core's query visitor, the tokens can't be
// filtered using token.Authorization.Id.Equals(key). To work around this issue,
// this compiled query uses an explicit join before applying the equality check.
@ -281,7 +281,7 @@ namespace OpenIddict.EntityFrameworkCore
/// <summary>
/// Exposes a compiled query allowing to retrieve a token using its unique identifier.
/// </summary>
private static Func<TContext, TKey, Task<TToken>> FindById =
private static readonly Func<TContext, TKey, Task<TToken>> FindById =
EF.CompileAsyncQuery((TContext context, TKey identifier) =>
(from token in context.Set<TToken>()
.Include(token => token.Application)
@ -313,7 +313,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve the list of
/// tokens corresponding to the specified reference identifier.
/// </summary>
private static Func<TContext, string, Task<TToken>> FindByReferenceId =
private static readonly Func<TContext, string, Task<TToken>> FindByReferenceId =
EF.CompileAsyncQuery((TContext context, string identifier) =>
(from token in context.Set<TToken>()
.Include(token => token.Application)
@ -346,7 +346,7 @@ namespace OpenIddict.EntityFrameworkCore
/// Exposes a compiled query allowing to retrieve the
/// list of tokens corresponding to the specified subject.
/// </summary>
private static Func<TContext, string, AsyncEnumerable<TToken>> FindBySubject =
private static readonly Func<TContext, string, AsyncEnumerable<TToken>> FindBySubject =
EF.CompileAsyncQuery((TContext context, string subject) =>
from token in context.Set<TToken>()
.Include(token => token.Application)

1
src/OpenIddict.MongoDb/OpenIddict.MongoDb.csproj

@ -21,6 +21,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="$(AspNetCoreVersion)" />
<PackageReference Include="MongoDB.Driver" Version="$(MongoDbVersion)" />
</ItemGroup>

2
src/OpenIddict.MongoDb/OpenIddictMongoDbExtensions.cs

@ -29,6 +29,8 @@ namespace Microsoft.Extensions.DependencyInjection
throw new ArgumentNullException(nameof(builder));
}
builder.Services.AddMemoryCache();
builder.SetDefaultApplicationEntity<OpenIddictApplication>()
.SetDefaultAuthorizationEntity<OpenIddictAuthorization>()
.SetDefaultScopeEntity<OpenIddictScope>()

3
src/OpenIddict.Server/OpenIddictServerExtensions.cs

@ -33,6 +33,9 @@ namespace Microsoft.Extensions.DependencyInjection
}
builder.Services.AddAuthentication();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddMemoryCache();
builder.Services.AddOptions();
builder.Services.TryAddScoped<IOpenIddictServerEventService, OpenIddictServerEventService>();
builder.Services.TryAddScoped<OpenIddictServerHandler>();

1
src/OpenIddict.Validation/OpenIddictValidationExtensions.cs

@ -33,6 +33,7 @@ namespace Microsoft.Extensions.DependencyInjection
}
builder.Services.AddAuthentication();
builder.Services.AddOptions();
builder.Services.TryAddScoped<IOpenIddictValidationEventService, OpenIddictValidationEventService>();
builder.Services.TryAddScoped<OpenIddictValidationHandler>();

Loading…
Cancel
Save