Browse Source

Bring back store registration methods supporting open generics

pull/2281/head
Kévin Chalet 11 months ago
parent
commit
22ebaa0bce
  1. 92
      src/OpenIddict.Core/OpenIddictCoreBuilder.cs

92
src/OpenIddict.Core/OpenIddictCoreBuilder.cs

@ -104,6 +104,29 @@ public sealed class OpenIddictCoreBuilder
return this; return this;
} }
/// <summary>
/// Replaces the application store by the specified type.
/// </summary>
/// <remarks>
/// Note: the specified type MUST be an open generic type definition containing exactly one generic argument.
/// </remarks>
/// <param name="type">The type of the store.</param>
/// <param name="lifetime">The lifetime of the store.</param>
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder ReplaceApplicationStore(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
if (!type.IsGenericTypeDefinition || type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
Services.Replace(ServiceDescriptor.Describe(typeof(IOpenIddictApplicationStore<>), type, lifetime));
return this;
}
/// <summary> /// <summary>
/// Replaces the authorization manager by the specified type. /// Replaces the authorization manager by the specified type.
/// </summary> /// </summary>
@ -161,6 +184,29 @@ public sealed class OpenIddictCoreBuilder
return this; return this;
} }
/// <summary>
/// Replaces the authorization store by the specified type.
/// </summary>
/// <remarks>
/// Note: the specified type MUST be an open generic type definition containing exactly one generic argument.
/// </remarks>
/// <param name="type">The type of the store.</param>
/// <param name="lifetime">The lifetime of the store.</param>
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder ReplaceAuthorizationStore(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
if (!type.IsGenericTypeDefinition || type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
Services.Replace(ServiceDescriptor.Describe(typeof(IOpenIddictAuthorizationStore<>), type, lifetime));
return this;
}
/// <summary> /// <summary>
/// Replaces the scope manager by the specified type. /// Replaces the scope manager by the specified type.
/// </summary> /// </summary>
@ -218,6 +264,29 @@ public sealed class OpenIddictCoreBuilder
return this; return this;
} }
/// <summary>
/// Replaces the scope store by the specified type.
/// </summary>
/// <remarks>
/// Note: the specified type MUST be an open generic type definition containing exactly one generic argument.
/// </remarks>
/// <param name="type">The type of the store.</param>
/// <param name="lifetime">The lifetime of the store.</param>
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder ReplaceScopeStore(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
if (!type.IsGenericTypeDefinition || type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
Services.Replace(ServiceDescriptor.Describe(typeof(IOpenIddictScopeStore<>), type, lifetime));
return this;
}
/// <summary> /// <summary>
/// Replaces the token manager by the specified type. /// Replaces the token manager by the specified type.
/// </summary> /// </summary>
@ -275,6 +344,29 @@ public sealed class OpenIddictCoreBuilder
return this; return this;
} }
/// <summary>
/// Replaces the token store by the specified type.
/// </summary>
/// <remarks>
/// Note: the specified type MUST be an open generic type definition containing exactly one generic argument.
/// </remarks>
/// <param name="type">The type of the store.</param>
/// <param name="lifetime">The lifetime of the store.</param>
/// <returns>The <see cref="OpenIddictCoreBuilder"/> instance.</returns>
public OpenIddictCoreBuilder ReplaceTokenStore(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
ServiceLifetime lifetime = ServiceLifetime.Scoped)
{
if (!type.IsGenericTypeDefinition || type.GetGenericArguments() is not { Length: 1 })
{
throw new ArgumentException(SR.GetResourceString(SR.ID0232), nameof(type));
}
Services.Replace(ServiceDescriptor.Describe(typeof(IOpenIddictTokenStore<>), type, lifetime));
return this;
}
/// <summary> /// <summary>
/// Disables additional filtering so that the OpenIddict managers don't execute a second check /// Disables additional filtering so that the OpenIddict managers don't execute a second check
/// to ensure the results returned by the stores exactly match the specified query filters, /// to ensure the results returned by the stores exactly match the specified query filters,

Loading…
Cancel
Save