-
-
Notifications
You must be signed in to change notification settings - Fork 265
Add support for keyed DI and update target frameworks #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Introduced `FromKeyedServicesAttribute` for resolving services by key in method parameters. Updated `ReflectionHelper` to handle keyed service resolution using `IKeyedServiceProvider`. Added tests to validate this functionality. Upgraded target frameworks to `net8.0` and `net9.0` across projects. Simplified reflection code by replacing `Array.Empty<object>()` with `[]`. Updated dependencies to use `Microsoft.Extensions.DependencyInjection.Abstractions` and newer versions of related packages. Enhanced test coverage with new tests for keyed DI and fixed typos in test method names. Adjusted project files to include additional package references and modernized exception messages for consistency.
Merged main branch into PR natemcmaster#560 to incorporate recent changes including: - Updated package versions - Target framework changes to net8.0 Resolved merge conflicts in: - McMaster.Extensions.CommandLineUtils.csproj - McMaster.Extensions.CommandLineUtils.Tests.csproj 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Three sample projects were still targeting net6.0 which is incompatible with the main library now targeting net8.0. Updated: - helloworld - helloworld-async - helloworld-attributes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
- Coverage 77.79% 77.74% -0.05%
==========================================
Files 104 104
Lines 3333 3339 +6
Branches 728 731 +3
==========================================
+ Hits 2593 2596 +3
- Misses 580 581 +1
- Partials 160 162 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @Chris-Wolfgang . I pushed some updates to get this change to build with GitHub CI to validate it works. The main library currently has no external package dependencies. Adding Microsoft.Extensions.DependencyInjection.Abstractions as a hard requirement would force all users to take this dependency, even if they don't use DI, and break the "minimal dependencies" philosophy of the core library. What do you think about some of these alternatives? Option 1: Reflection-based detection Use reflection to detect if the keyed services types are available at runtime, without a compile-time dependency. The feature works automatically when users have the DI abstractions available; otherwise it's silently ignored (or throws a clear error only when someone actually uses Pros: No new dependencies, works if user brings their own DI Option 2: Separate package Create a new package like Pros: Clean separation of concerns I'm inclined toward Option 1 since it preserves the zero-dependency nature of the core library while still enabling the feature for users who have the DI abstractions. What do you think? |
Resolves #552 and #558
Introduced
FromKeyedServicesAttributefor resolving services by key in method parameters. UpdatedReflectionHelperto handle keyed service resolution usingIKeyedServiceProvider. Added tests to validate this functionality.Upgraded target frameworks to
net8.0across projects and updated test to target 8.0 and 9.0. Simplified reflection code by replacingArray.Empty<object>()with[]. Updated dependencies to useMicrosoft.Extensions.DependencyInjection.Abstractionsand newer versions of related packages.Enhanced test coverage with new tests for keyed DI and fixed typos in test method names. Adjusted project files to include additional package references and modernized exception messages for consistency.