Engine: Split FHIR facade services from MVC#1262
Conversation
There was a problem hiding this comment.
Pull request overview
This PR decouples the Spark Engine “FHIR facade” service-layer registrations from ASP.NET Core MVC, enabling consumers to register the facade without implicitly adding controllers/formatters, while preserving the prior behavior behind an explicit MVC-oriented extension method.
Changes:
- Added
AddFhirFacadeServicesto register the FHIR facade service layer without callingAddControllers/ MVC service registration. - Added
AddFhirFacadeMvcas the explicit MVC-based facade setup and markedAddFhirFacadeobsolete to guide migration. - Moved MVC formatter service registrations behind a dedicated helper and added a contract test ensuring MVC-free facade registration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Tests/Spark.Engine.R4.Tests/Extensions/FhirFacadeServiceCollectionExtensionsTests.cs | Adds a contract test verifying AddFhirFacadeServices does not register MVC/controller-related services while still registering required facade components. |
| Libraries/Spark.Engine/Extensions/IServiceCollectionExtensions.cs | Introduces the new facade registration APIs, routes legacy AddFhirFacade to the MVC path, and isolates MVC formatter registrations behind a helper. |
Comments suppressed due to low confidence (1)
Libraries/Spark.Engine/Extensions/IServiceCollectionExtensions.cs:104
AddFhirFacadeServicesInternalbuilds a temporaryServiceProviderto read configuredSparkOptions, but it is never disposed. Wrap theBuildServiceProvider()result in ausing/using varto avoid leaking the root provider (and any transient/singleton disposables created during resolution).
services.Configure(options);
var serviceProvider = services.BuildServiceProvider();
var opts = serviceProvider.GetRequiredService<IOptions<SparkOptions>>()?.Value;
var settings = opts.Settings;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| private static void AddFhirMvcFormatterServices(this IServiceCollection services) | ||
| { |
There was a problem hiding this comment.
Good catch — Iremoved AddFhirMvcFormatterServices entirely in a follow-up instead. Nothing in Applications/ or Libraries/ resolves these four formatters from DI; they're constructed manually inside AddFhirFormatters (with ArrayPool.Shared) and inserted into MvcOptions.InputFormatters/OutputFormatters. The TryAddTransient lines seems to be dead code — the bug only surfaced because the new test was the first thing that tried to resolve them?
Introduce AddFhirFacadeServices for registering the FHIR facade service layer without calling AddControllers or registering MVC formatter services. Add AddFhirFacadeMvc as the explicit replacement for the previous MVC-based facade setup, and mark AddFhirFacade obsolete so users get a clear migration path. Drop the TryAddTransient registrations for ResourceJson/XmlInput/OutputFormatter from both the facade and AddFhirInternal — nothing resolved them from DI, and the formatters are still constructed manually and inserted into MvcOptions.InputFormatters/OutputFormatters by AddFhirFormatters when wiring up the MVC pipeline. Add a contract test covering the MVC-free facade registration.
54b6427 to
8c25f91
Compare
Introduce AddFhirFacadeServices for registering the FHIR facade service layer without calling AddControllers or registering MVC formatter services.
Add AddFhirFacadeMvc as the explicit replacement for the previous MVC-based facade setup, and mark AddFhirFacade obsolete so beta users get a clear migration path.
Move FHIR MVC formatter service registrations behind AddFhirMvcFormatterServices and add a contract test covering the MVC-free facade registration.