-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
[proposal] Auto magically inject services #28
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportBase: 89.56% // Head: 87.85% // Decreases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #28 +/- ##
==========================================
- Coverage 89.56% 87.85% -1.71%
==========================================
Files 6 7 +1
Lines 460 527 +67
==========================================
+ Hits 412 463 +51
- Misses 40 52 +12
- Partials 8 12 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
If I wanted to use Uber Fx, I'd just use Uber Fx. DI without reflection is one of the biggest advantages |
@counterposition without reflection? Ok, very good, but uses assertion, and assertion is not safe type like this package says in readme.MD ("type safe"). https://github.com/samber/do/blob/master/injector.go#L57 What is the problem to use reflect? The generics here is a fake, is just to generate names for a |
Linked to #9
This contribution adds support for a service declaration in struct tags. Such as:
In this proposal, I suggest 3 new helpers:
do.InjectTag(do.Injector, Service) (Service, error)
do.MustInjectTag(do.Injector, Service) (Service)
do.TagProvider[T any](t T) Provider[T]
This implementation is obviously unsafe since it uses
reflect
andunsafe
std libs.Example:
IMO, we should avoid calling this helper automatically on service invocation. It would be error-prone and costly. Being declarative also allows the developer to execute
do.InjectTag
at the right time in the provider.do.TagProvider
would be a shortcut for very simple providers:I would be very happy to receive feedback about this!