Skip to content

Use same IConnectionMultiplexer for redis backplance, locker and cache (#12221)#12222

Open
yasmoradi wants to merge 9 commits intobitfoundation:developfrom
yasmoradi:12221
Open

Use same IConnectionMultiplexer for redis backplance, locker and cache (#12221)#12222
yasmoradi wants to merge 9 commits intobitfoundation:developfrom
yasmoradi:12221

Conversation

@yasmoradi
Copy link
Copy Markdown
Member

@yasmoradi yasmoradi commented Mar 28, 2026

closes #12221

Summary by CodeRabbit

  • Refactor
    • Improved infrastructure stability through optimized connection management for caching and distributed locking services.

@yasmoradi yasmoradi requested a review from Copilot March 28, 2026 19:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f6e7100-f5f0-4505-b40d-9b743612f0de

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Redis configuration in the Boilerplate template was refactored to use keyed services consistently across distributed cache, backplane, and locker components. A new post-configurator class handles centralized Redis options configuration, and conditional template exclusion was added for the legacy configurator when Redis is disabled.

Changes

Cohort / File(s) Summary
Template Configuration
.template.config/template.json
Added conditional exclusion of AppRedisConfigurator.cs when Redis is disabled (redis == false).
Service Registration
Infrastructure/Extensions/WebApplicationBuilderExtensions.cs
Migrated to keyed Redis client registration (AddKeyedRedisClient for persistent Redis), replaced inline Redis fluent configuration with grouped setup methods (AddFusionCacheRedisDistributedLocker, AddFusionCacheStackExchangeRedisBackplane, ConfigureRedisOptions), and updated distributed cache backing to use parameterless configuration.
Service Resolution
Program.Services.cs
Updated Medallion and Hangfire Redis dependency resolution to use keyed service lookup (GetRequiredKeyedService<IConnectionMultiplexer>("redis-persistent")) instead of unkeyed retrieval.
Redis Post-Configuration
Infrastructure/Services/AppRedisCacheConfigurator.cs
New post-configurator class implementing multi-interface pattern (IPostConfigureOptions<RedisCacheOptions>, IPostConfigureOptions<RedisDistributedLockerOptions>, IPostConfigureOptions<RedisBackplaneOptions>) to centrally configure ConnectionMultiplexerFactory across Redis-dependent components using keyed service injection.

Sequence Diagram(s)

sequenceDiagram
    participant DI as DI Container
    participant ARC as AppRedisCacheConfigurator
    participant Cache as RedisCacheOptions
    participant Backplane as RedisBackplaneOptions
    participant Locker as RedisDistributedLockerOptions
    participant CM as IConnectionMultiplexer

    DI->>ARC: PostConfigure (Cache)
    ARC->>CM: Resolve "redis-cache"
    CM-->>ARC: Instance returned
    ARC->>Cache: Set ConnectionMultiplexerFactory

    DI->>ARC: PostConfigure (Backplane)
    ARC->>CM: Resolve "redis-cache"
    CM-->>ARC: Instance returned
    ARC->>Backplane: Set ConnectionMultiplexerFactory

    DI->>ARC: PostConfigure (Locker)
    ARC->>CM: Resolve "redis-cache"
    CM-->>ARC: Instance returned
    ARC->>Locker: Set ConnectionMultiplexerFactory
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰✨ Redis Reborn

Keyed services dance in harmony today,
One multiplexer leads the cached way,
Post-configuration blooms so fine,
Cache, backplane, and locker align,
The boilerplate hops with cleaner design!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly describes the main objective: ensuring the same IConnectionMultiplexer is used for Redis backplane, locker, and cache across the codebase.
Linked Issues check ✅ Passed All code changes implement the requirement from issue #12221: the same IConnectionMultiplexer instance is now shared across Redis Distributed Cache, Distributed Locker, and Backplane components.
Out of Scope Changes check ✅ Passed All modifications are directly related to the Redis configuration objective; no unrelated or out-of-scope changes are present in the PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

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

Improves the Bit Boilerplate Redis setup so FusionCache’s L2 distributed cache, distributed locker, and Redis backplane can share a single IConnectionMultiplexer, matching the intent in #12221.

Changes:

  • Added an IPostConfigureOptions-based configurator to wire ConnectionMultiplexerFactory for Redis cache/backplane/locker options.
  • Updated server shared service registration to use FusionCache Redis integration extensions and centralize Redis options wiring.
  • Updated the template to exclude the new configurator file when redis == false.

Reviewed changes

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

File Description
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisConfigurator.cs Adds shared Redis options post-configuration intended to reuse a single multiplexer across cache/backplane/locker.
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs Switches FusionCache Redis wiring to package-provided registrations and uses ConfigureRedisOptions() to centralize multiplexer sharing.
src/Templates/Boilerplate/Bit.Boilerplate/.template.config/template.json Ensures the new Redis-only file is excluded when the template is generated with Redis disabled.

@yasmoradi yasmoradi requested a review from Copilot March 28, 2026 19:52
@yasmoradi
Copy link
Copy Markdown
Member Author

@coderabbitai re-review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 28, 2026

@yasmoradi Sure, I'll re-review the changes in this PR right away!

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

…te.Server.Shared/Infrastructure/Services/AppRedisCacheConfigurator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Yas Moradi <yas_moradi@outlook.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs (1)

87-91: Reliance on post-configurator for Redis connection.

The empty lambda (_ => { }) works because AppRedisCacheConfigurator sets ConnectionMultiplexerFactory via IPostConfigureOptions. Consider adding a brief inline comment to clarify this dependency for maintainability.

💡 Suggested clarification
         // Registering Microsoft's IDistributedCache here doesn't mean you have to use it in your code. It's only for libraries that might rely on it.
         //#if(redis == true)
-        services.AddStackExchangeRedisCache(_ => { });
+        services.AddStackExchangeRedisCache(_ => { }); // Connection configured via AppRedisCacheConfigurator post-configurator
         //#else
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs`
around lines 87 - 91, The empty lambda passed to
services.AddStackExchangeRedisCache(_ => { }) relies on
AppRedisCacheConfigurator to populate ConnectionMultiplexerFactory via an
IPostConfigureOptions implementation; add a short inline comment next to the
AddStackExchangeRedisCache call noting this dependency (mention
AppRedisCacheConfigurator, ConnectionMultiplexerFactory and
IPostConfigureOptions) so future maintainers understand why the lambda is empty
and that configuration is applied in post-configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Templates/Boilerplate/Bit.Boilerplate/.template.config/template.json`:
- Around line 599-604: The template's exclude entry under the condition "(redis
== false)" references the wrong filename; update the exclude array in
.template.config/template.json so it excludes the actual Redis configurator file
name used in the PR (replace "AppRedisConfigurator.cs" with
"AppRedisCacheConfigurator.cs" or include both names) to ensure the Redis
configurator (AppRedisCacheConfigurator.cs) is omitted when redis == false.

In
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisCacheConfigurator.cs`:
- Around line 9-10: Fix the typo in the XML summary comment for the
AppRedisCacheConfigurator description: replace the misspelled word "enrhiched"
with "enriched" in the summary that reads "Configures FusionCache L2,
Distributed Locking, and Backplane to share a single Redis connection enrhiched
with logging and retry policies." so the class/method documentation
(AppRedisCacheConfigurator) uses "enriched".

---

Nitpick comments:
In
`@src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs`:
- Around line 87-91: The empty lambda passed to
services.AddStackExchangeRedisCache(_ => { }) relies on
AppRedisCacheConfigurator to populate ConnectionMultiplexerFactory via an
IPostConfigureOptions implementation; add a short inline comment next to the
AddStackExchangeRedisCache call noting this dependency (mention
AppRedisCacheConfigurator, ConnectionMultiplexerFactory and
IPostConfigureOptions) so future maintainers understand why the lambda is empty
and that configuration is applied in post-configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3e5738cd-acef-434f-b7ea-e9238b28a3b5

📥 Commits

Reviewing files that changed from the base of the PR and between b23cb12 and 6b769a9.

📒 Files selected for processing (4)
  • src/Templates/Boilerplate/Bit.Boilerplate/.template.config/template.json
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Program.Services.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cs
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisCacheConfigurator.cs

@yasmoradi yasmoradi requested a review from msynk March 28, 2026 20:15
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bit Boilerplate redis configuration needs improvements

2 participants