Skip to content

Conversation

@kzu
Copy link
Member

@kzu kzu commented Nov 12, 2024

A new overload of AddServices allows passing a type and/or a regex to evaluate against types in the current compilation (at compile-time) and emit registrations for all of them, just as if they had been annotated with a corresponding [Service] attribute.

Key-based registrations not supported for this mechanism since it's not clear how to express a dynamic key based on either the type or regex that can be evaluated by the source generator.

Instead of adding a separte assembly-level attribute, extending the existing API with this pseudo-reflection approach is far more discoverable.

Fixes #116

A new overload of `AddServices` allows passing a type and/or a regex to evaluate against types in the current compilation (at compile-time) and emit registrations for all of them, just as if they had been annotated with a corresponding `[Service]` attribute.

Key-based registrations not supported for this mechanism since it's not clear how to express a dynamic key based on either the type or regex that can be evaluated by the source generator.

Instead of adding a separte assembly-level attribute, extending the existing API with this pseudo-reflection approach is far more discoverable.

Fixes #116
@kzu kzu added the enhancement New feature or request label Nov 12, 2024
@devlooped-bot
Copy link
Member

10 passed 10 passed

🧪 Details on Ubuntu 22.04.5 LTS

✅ Tests.CodeAnalysis.AddServicesAnalyzerTests.NoWarningIfAddServicesPresent
✅ Tests.CodeAnalysis.AddServicesAnalyzerTests.NoWarningIfNoServiceCollectionCalls
✅ Tests.CodeAnalysis.AddServicesAnalyzerTests.WarnIfAddServicesMissing
✅ Tests.CodeAnalysis.AddServicesAnalyzerTests.WarnIfAddServicesMissingMultipleLocations
✅ Tests.CodeAnalysis.ConventionAnalyzerTests.ErrorIfNonTypeOf
✅ Tests.CodeAnalysis.ConventionAnalyzerTests.NoErrorOnTypeOfAndLifetime
✅ Tests.CodeAnalysis.ConventionAnalyzerTests.WarnIfOpenGeneric
✅ Tests.DependencyInjection.ConventionsTests.RegisterGenericServices
✅ Tests.DependencyInjection.ConventionsTests.RegisterRepositoryServices
✅ Tests.DependencyInjection.ConventionsTests.RegisterServiceByRegex

from dotnet-retest v0.6.3 on .NET 8.0.10 with 💜

@kzu kzu merged commit a16baae into main Nov 12, 2024
@kzu kzu deleted the dev/conventions branch November 12, 2024 18:04
@devlooped devlooped locked and limited conversation to collaborators Dec 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide conventions-based registrations in addition to [Service] attributes

3 participants