Skip to content

Extract Program.cs into reusable AddRiftCacheCore()/MapRiftCacheCore() - #16

Merged
vectorloom merged 1 commit into
mainfrom
refactor/extract-riftcache-core-composition
Aug 15, 2026
Merged

vectorloom merged 1 commit into
mainfrom
refactor/extract-riftcache-core-composition

Conversation

@vectorloom

Copy link
Copy Markdown
Owner

First, standalone-valuable piece of the "wire AzureBlobPersistenceProvider into the Azure Container Apps deployment" ROADMAP follow-up. Program.cs was plain top-level statements -- no way for a different composed entry point (the future RiftCache.Azure project) to reuse the core service's wiring without copy-pasting it. Fixes that generally: any future provider (AWS, GCP, or a second Azure variant) needs the same composability, not just this one.

Pure behavior-preserving extraction, verified as such rather than assumed: the existing WebApplicationFactory-based integration tests (CacheEndpointsTests, MultiTenantCacheEndpointsTests) boot the whole app and exercise every route, and all 73 existing tests pass completely unchanged. Also ran the refactored service directly and re-exercised the full single-tenant curl flow (root banner, healthz, 401/set/get/refresh/delete) to confirm real runtime behavior matches, not just what the automated tests happen to cover -- multi-tenant wasn't manually re-verified this way since Bash doesn't support hyphens in env var names (RIFTCACHE_API_KEY__TEAM-A isn't valid VAR=value syntax), but MultiTenantCacheEndpointsTests already covers that exact code path and passed.

AddRiftCacheCore(IServiceCollection, IConfiguration) in the new RiftCacheServiceCollectionExtensions.cs moves every DI registration verbatim. MapRiftCacheCore(IEndpointRouteBuilder, RiftCacheServerOptions) in RiftCacheEndpointRouteBuilderExtensions.cs wraps the root banner, /healthz, and the existing MapCacheEndpoints call -- CacheEndpoints.cs itself is untouched.

One real fix along the way, not just relocation: the root banner's version lookup used typeof(Program).Assembly, which only worked because Program lived in this same file/project. Now that this logic is reusable, it's anchored to typeof(RiftCacheServerOptions) instead -- a type guaranteed to live in the core assembly regardless of which entry point (this one, or a future composed one) actually hosts it. Confirmed via curl that the banner still reports the correct version after the change.

Added RiftCacheServiceCollectionExtensionsTests.cs with the test that actually matters for this refactor's stated purpose: registering AddRiftCacheCore() then a fake IPersistenceProvider afterward resolves to the fake, not the default -- proving the "last registration wins, so a composed entry point can layer Azure providers on top without a removal step" claim actually holds, not just asserting it in a comment.

Also fixed two more stale ARCHITECTURE_NOTES.md references (renamed to ARCHITECTURE.md several PRs ago) found while touching this area -- grepped the whole repo afterward to confirm none remain.

First, standalone-valuable piece of the "wire AzureBlobPersistenceProvider
into the Azure Container Apps deployment" ROADMAP follow-up. Program.cs
was plain top-level statements -- no way for a different composed entry
point (the future RiftCache.Azure project) to reuse the core service's
wiring without copy-pasting it. Fixes that generally: any future
provider (AWS, GCP, or a second Azure variant) needs the same
composability, not just this one.

Pure behavior-preserving extraction, verified as such rather than
assumed: the existing WebApplicationFactory<Program>-based integration
tests (CacheEndpointsTests, MultiTenantCacheEndpointsTests) boot the
whole app and exercise every route, and all 73 existing tests pass
completely unchanged. Also ran the refactored service directly and
re-exercised the full single-tenant curl flow (root banner, healthz,
401/set/get/refresh/delete) to confirm real runtime behavior matches,
not just what the automated tests happen to cover -- multi-tenant
wasn't manually re-verified this way since Bash doesn't support
hyphens in env var names (RIFTCACHE_API_KEY__TEAM-A isn't valid
`VAR=value` syntax), but MultiTenantCacheEndpointsTests already covers
that exact code path and passed.

AddRiftCacheCore(IServiceCollection, IConfiguration) in the new
RiftCacheServiceCollectionExtensions.cs moves every DI registration
verbatim. MapRiftCacheCore(IEndpointRouteBuilder, RiftCacheServerOptions)
in RiftCacheEndpointRouteBuilderExtensions.cs wraps the root banner,
/healthz, and the existing MapCacheEndpoints call -- CacheEndpoints.cs
itself is untouched.

One real fix along the way, not just relocation: the root banner's
version lookup used typeof(Program).Assembly, which only worked
because Program lived in this same file/project. Now that this logic
is reusable, it's anchored to typeof(RiftCacheServerOptions) instead --
a type guaranteed to live in the core assembly regardless of which
entry point (this one, or a future composed one) actually hosts it.
Confirmed via curl that the banner still reports the correct version
after the change.

Added RiftCacheServiceCollectionExtensionsTests.cs with the test that
actually matters for this refactor's stated purpose: registering
AddRiftCacheCore() then a fake IPersistenceProvider afterward resolves
to the fake, not the default -- proving the "last registration wins,
so a composed entry point can layer Azure providers on top without a
removal step" claim actually holds, not just asserting it in a
comment.

Also fixed two more stale ARCHITECTURE_NOTES.md references (renamed to
ARCHITECTURE.md several PRs ago) found while touching this area --
grepped the whole repo afterward to confirm none remain.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vectorloom
vectorloom merged commit 7724108 into main Aug 15, 2026
2 checks passed
@vectorloom
vectorloom deleted the refactor/extract-riftcache-core-composition branch August 16, 2026 15:00
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.

1 participant