Use same IConnectionMultiplexer for redis backplance, locker and cache (#12221)#12222
Use same IConnectionMultiplexer for redis backplance, locker and cache (#12221)#12222yasmoradi wants to merge 9 commits intobitfoundation:developfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughRedis 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 wireConnectionMultiplexerFactoryfor 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. |
...erplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisConfigurator.cs
Outdated
Show resolved
Hide resolved
...erplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisConfigurator.cs
Outdated
Show resolved
Hide resolved
...erplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisConfigurator.cs
Outdated
Show resolved
Hide resolved
|
@coderabbitai re-review |
|
✅ Actions performedFull review triggered. |
src/Templates/Boilerplate/Bit.Boilerplate/.template.config/template.json
Show resolved
Hide resolved
...te/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisCacheConfigurator.cs
Outdated
Show resolved
Hide resolved
…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>
There was a problem hiding this comment.
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 becauseAppRedisCacheConfiguratorsetsConnectionMultiplexerFactoryviaIPostConfigureOptions. 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
📒 Files selected for processing (4)
src/Templates/Boilerplate/Bit.Boilerplate/.template.config/template.jsonsrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Program.Services.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Extensions/WebApplicationBuilderExtensions.cssrc/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Shared/Infrastructure/Services/AppRedisCacheConfigurator.cs
closes #12221
Summary by CodeRabbit