Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/OpenIddict.Core/OpenIddictCoreBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ public OpenIddictCoreBuilder ReplaceApplicationStore<
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>
/// Replaces the authorization manager by the specified type.
/// </summary>
Expand Down Expand Up @@ -161,6 +184,29 @@ public OpenIddictCoreBuilder ReplaceAuthorizationStore<
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>
/// Replaces the scope manager by the specified type.
/// </summary>
Expand Down Expand Up @@ -218,6 +264,29 @@ public OpenIddictCoreBuilder ReplaceScopeStore<
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>
/// Replaces the token manager by the specified type.
/// </summary>
Expand Down Expand Up @@ -275,6 +344,29 @@ public OpenIddictCoreBuilder ReplaceTokenStore<
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>
/// 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,
Expand Down