Skip to content

feat(DataProtection): add overloads for PersistKeysToStackExchangeRedis to accept IServiceProvider #62759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hangy
Copy link
Contributor

@hangy hangy commented Jul 16, 2025

Add additional overloads to PersistKeysToStackExchangeRedis

Enhances the DataProtection library by enabling it to use an existing connection

Description

The additional overloads of the PersistKeysToStackExchangeRedis extension method allow an externally configured Redis connection from Aspire to be used to persist the data protection keys.

Fixes #61768

@Copilot Copilot AI review requested due to automatic review settings July 16, 2025 18:33
@github-actions github-actions bot added the area-dataprotection Includes: DataProtection label Jul 16, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 16, 2025
Copy link
Contributor

Thanks for your PR, @@hangy. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

Copilot

This comment was marked as outdated.

@hangy hangy requested a review from Copilot July 16, 2025 18:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds new overloads for PersistKeysToStackExchangeRedis that take an IServiceProvider-based factory for the Redis IDatabase, updates the internal wiring to use IConfigureOptions, and surfaces the changes in the public API.

  • Introduces two overloads accepting Func<IServiceProvider, IDatabase> with optional custom RedisKey
  • Modifies internal method to register a singleton IConfigureOptions<KeyManagementOptions> that defers to the IServiceProvider
  • Updates PublicAPI.Unshipped.txt and adds a test for the factory-based overload

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/DataProtection/StackExchangeRedis/test/RedisDataProtectionBuilderExtensionsTest.cs Adds a test for the IServiceProvider factory overload
src/DataProtection/StackExchangeRedis/src/RedisDataProtectionBuilderExtensions.cs Implements new overloads and adjusts internal configuration DI
src/DataProtection/StackExchangeRedis/src/PublicAPI.Unshipped.txt Exposes the new overloads in the public API surface
Comments suppressed due to low confidence (3)

src/DataProtection/StackExchangeRedis/src/PublicAPI.Unshipped.txt:2

  • The PublicAPI entry references StackExchangeRedisDataProtectionBuilderExtensions, but the actual static class in code is named RedisDataProtectionBuilderExtensions. Update the API file to the correct class name.
static Microsoft.AspNetCore.DataProtection.StackExchangeRedisDataProtectionBuilderExtensions.PersistKeysToStackExchangeRedis(this Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder! builder, System.Func<System.IServiceProvider!, StackExchange.Redis.IDatabase!>! databaseFactory) -> Microsoft.AspNetCore.DataProtection.IDataProtectionBuilder!

src/DataProtection/StackExchangeRedis/test/RedisDataProtectionBuilderExtensionsTest.cs:32

  • There's a factory-based overload test but no test for the overload that takes a custom RedisKey. Consider adding a test that passes a non-default RedisKey and asserts the RedisXmlRepository uses that key.
    [Fact]

src/DataProtection/StackExchangeRedis/test/RedisDataProtectionBuilderExtensionsTest.cs:41

  • The test invokes a database factory that depends on IConnectionMultiplexer, but IConnectionMultiplexer is never registered in the ServiceCollection. Add something like serviceCollection.AddSingleton<IConnectionMultiplexer>(connection); before calling the builder method.
        builder.PersistKeysToStackExchangeRedis(services => services.GetRequiredService<IConnectionMultiplexer>().GetDatabase());

Comment on lines +87 to +91
builder.Services.AddSingleton<IConfigureOptions<KeyManagementOptions>>(services =>
{
options.XmlRepository = new RedisXmlRepository(databaseFactory, key);
return new ConfigureOptions<KeyManagementOptions>(options =>
{
options.XmlRepository = new RedisXmlRepository(() => databaseFactory(services), key);
Copy link
Preview

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The lambda parameter services shadows the builder.Services property and may confuse readers. Consider renaming the parameter to sp or serviceProvider to clarify its purpose.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dataprotection Includes: DataProtection community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add PersistKeysToStackExchangeRedis overload which accepts Func<IServiceProvider, IDatabase>
1 participant