Repository navigation
Support single-file published apps - #390
Merged
Merged
Conversation
DependencyContext.Load() returns null for single-file published apps, causing AddCarter() to fail during startup. Fall back to AppDomain.CurrentDomain.GetAssemblies() when DependencyContext is unavailable. Also skip open generic validators during discovery, since the fallback scans FluentValidation's own assembly and those types cannot be registered in DI.
In single-file published apps the DependencyContext is either null (self-contained) or only describes the shared framework (framework-dependent), so AddCarter either threw or found no modules. When the DependencyContext yields no library referencing Carter or FluentValidation, walk the assembly references of the entry assembly instead and scan the assemblies that reference Carter or FluentValidation. This replaces scanning every loaded assembly. Add unit tests, a single-file smoke test that runs in CI and README documentation. Co-Authored-By: Claude <noreply@anthropic.com>
Add a sample app that is published as a single file, with a module and validator of its own and a validator in the referenced ValidatorOnlyProject. Point the single-file smoke test at the new sample and split the script into small functions. Run it as a step in the build job, before the packaging and push steps, so a failure blocks merging and publishing. The publish no longer regenerates the NuGet packages. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #386 and fixes #383. The first commit is @seifmaazouz's commit from #386, cherry-picked onto
main; the second builds on it.Problem
Carter discovers modules, validators and response negotiators from the app's
DependencyContext. In a single-file published app that context is not usable:DependencyContext.Load()nullNullReferenceExceptioninAddCarterThis is unchanged on .NET 11 (dotnet/runtime#70438 is still open).
Changes
DependencyContextyields no library referencing Carter or FluentValidation,DependencyContextAssemblyCatalogwalks the assembly references of the entry assembly and scans the assemblies that reference Carter or FluentValidation. Assemblies namedSystem.*orMicrosoft.*are not walked. This replaces Fix AddCarter when DependencyContext is unavailable in single-file publish #386's fallback of scanning every loaded assembly, and also covers the framework-dependent case.single-file-smoke-test.sh, run as a separate CI job, publishes the sample as a single file (framework-dependent and self-contained) and checks a route and a validator from a referenced project.Known limitation
The compiler drops references to assemblies whose types are never used in code, so a project referenced only for its modules or validators is not found by the walk. Those apps need to pass assemblies explicitly with
new DependencyContextAssemblyCatalog(assembly1, assembly2), which is documented in the README.🤖 Generated with Claude Code