Repository navigation
fix: always emit the Add<Assembly>Services extension - #236
Merged
Merged
Conversation
GenerateSources returned early when the assembly had no attributed services, so no extension and no container classes were emitted. A composition root that already called Add<Assembly>Services then failed with CS1061 until a placeholder service was added, and the same break happened when the last service was removed. The early return is gone. With zero services the extension just returns services, and with ZeroAlloc.Inject.Container referenced the empty provider classes are emitted too. The diagnostics path is separate and unchanged, so decorator diagnostics still work. Tests cover an assembly with no attributed types, with and without the container, and compile the generated output.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
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.
Summary
Problem:
Add<AssemblyName>Services()was generated only when the assembly had at least one[Transient],[Scoped]or[Singleton]type.GenerateSourcesreturned early on zero services, so a composition root that already called the extension failed with CS1061, for example in layered solutions or after the last service is removed.Before: no extension and no container classes for an assembly without attributed types.
After: the extension is always emitted and returns
serviceswhen there is nothing to register. With ZeroAlloc.Inject.Container referenced, the empty service provider classes are emitted as well.Changes
GenerateSources. The diagnostics path was already separate and is untouched, so decorator diagnostics behave as before.NoAttributedClasses_GeneratesNothingtest, which asserted nothing about output, to match the new behaviour.Tests
Behaviour change
An assembly with no attributed services now gets a public
Add<Assembly>Servicesextension, and with the Container referenced, empty service provider classes. Previously nothing was generated.Fixes #235