Open samber opened 1 year ago
Base: 89.56% // Head: 87.85% // Decreases project coverage by -1.71%
:warning:
Coverage data is based on head (
7a95bf7
) compared to base (16a48d1
). Patch coverage: 76.47% of modified lines in pull request are covered.
:mega: 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
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
If I wanted to use Uber Fx, I'd just use Uber Fx. DI without reflection is one of the biggest advantages do
has over Fx.
@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 https://github.com/samber/do/blob/master/injector.go#L177 https://github.com/samber/do/blob/master/injector.go#L201 https://github.com/samber/do/blob/master/di.go#L128
What is the problem to use reflect? The generics here is a fake, is just to generate names for a map[string]any
.
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!