Skip to content

fix(di): cache registry factory execution - #52

Merged
thomhurst merged 1 commit into
mainfrom
issue-25-di-registry
Aug 21, 2026
Merged

fix(di): cache registry factory execution#52
thomhurst merged 1 commit into
mainfrom
issue-25-di-registry

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • execute each named typed/untyped registry factory exactly once under concurrent first resolution
  • cache and rethrow factory construction failures consistently across registry, TryGet, and keyed DI paths
  • define case-sensitive/empty-name and factory-failure contracts; add exact null guards
  • reject unknown BackoffKind values instead of silently treating them as exponential
  • add table-driven registry and configuration coverage, including all strategy sections and backoff kinds

Closes #25

Validation

  • dotnet build Kevlar.slnx -c Release --no-incremental
  • dotnet run --project tests/Kevlar.Tests -c Release --no-build -- --timeout 5m (352 passed)
  • dotnet run --project tests/Kevlar.NetStandard.Tests -c Release --no-build -- --timeout 5m (1 passed)
  • dotnet run --project tests/Kevlar.IntegrationTests -c Release --no-build -- --timeout 5m (16 passed)
  • dotnet run --project tests/Kevlar.Analyzers.Tests -c Release --no-build -- --timeout 5m (19 passed)

Resolve each registration through one execution-and-publication Lazy so concurrent paths share the same shield or cached construction failure.
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@thomhurst, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Limit details: You’ve used all 10 included reviews currently available.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

Wait for the limit to reset, then comment @coderabbitai review or push new commits to the PR.

An organization admin can change what happens after included review limits in Billing.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6cf60d27-270b-4b89-abad-315a8b776bc7

📥 Commits

Reviewing files that changed from the base of the PR and between c3ffb96 and f4f7194.

📒 Files selected for processing (4)
  • src/Kevlar.Extensions.DependencyInjection/IKevlarRegistry.cs
  • src/Kevlar.Extensions.DependencyInjection/KevlarRegistry.cs
  • src/Kevlar.Extensions.DependencyInjection/ShieldDefinition.cs
  • tests/Kevlar.Tests/DependencyInjectionContractTests.cs

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

@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR makes named shield factory initialization concurrency-safe and caches both successful values and construction failures. It also validates unknown backoff enum values and adds DI/configuration contract coverage.

  • Wraps cached registry factories in execution-and-publication Lazy instances.
  • Applies exact null-name validation and documents naming and caching contracts.
  • Rejects unsupported BackoffKind values instead of defaulting to exponential backoff.
  • Adds concurrency, failure-caching, keyed-resolution, naming, registration, and configuration tests.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable defects identified in the changed behavior.

The singleton registry and keyed-service paths share the same Lazy cache, ensuring one factory execution and a consistent cached value or exception, while the stricter backoff validation matches the stated contract.

Important Files Changed

Filename Overview
src/Kevlar.Extensions.DependencyInjection/IKevlarRegistry.cs Documents case-sensitive naming and the shared value-or-exception caching contract.
src/Kevlar.Extensions.DependencyInjection/KevlarRegistry.cs Uses Lazy execution-and-publication semantics to ensure concurrent callers execute each factory once and share its outcome.
src/Kevlar.Extensions.DependencyInjection/ShieldDefinition.cs Explicitly rejects undefined BackoffKind values rather than interpreting them as exponential.
tests/Kevlar.Tests/DependencyInjectionContractTests.cs Adds broad contract coverage for concurrent DI resolution, cached failures, keyed paths, registration semantics, names, and configuration behavior.

Sequence Diagram

sequenceDiagram
    participant C1 as Concurrent caller 1
    participant C2 as Concurrent caller 2
    participant R as KevlarRegistry
    participant L as Cached Lazy
    participant F as Shield factory
    C1->>R: GetShield(name)
    C2->>R: GetShield(name)
    R->>L: GetOrAdd(key)
    R->>L: GetOrAdd(key)
    L->>F: Execute once
    F-->>L: Shield or exception
    L-->>R: Cached outcome
    R-->>C1: Same outcome
    R-->>C2: Same outcome
Loading

Reviews (1): Last reviewed commit: "fix(di): cache registry factory executio..." | Re-trigger Greptile

@thomhurst
thomhurst merged commit 0e18e77 into main Aug 21, 2026
7 checks passed
@thomhurst
thomhurst deleted the issue-25-di-registry branch August 21, 2026 11:49
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.

test(DI): make registry resolution and configuration contracts exhaustive

1 participant