-
-
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
[👷] Road to v2 🚀 #45
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "v2-\u{1F680}"
[👷] Road to v2 🚀 #45
Conversation
DebuggingHere is the output of Scope ID: scope-id-123
Scope name: scope-child
Service: SERVICE-E
Service type: lazy
Service build time: 1s
Invoked: /home/samber/project/github.com/samber/do/di_explain_test.go:fakeProvider5:38
Dependencies:
* SERVICE-D from scope scope-child
* SERVICE-C1 from scope scope-child
* SERVICE-B from scope [root]
* SERVICE-A1 from scope [root]
* SERVICE-A2 from scope [root]
* SERVICE-C2 from scope scope-child
* SERVICE-B from scope [root]
* SERVICE-A1 from scope [root]
* SERVICE-A2 from scope [root]
Dependents:
* SERVICE-F from scope scope-child
* SERVICE-G from scope scope-child Here is the output of Scope ID: scope-id-root
Scope name: [root]
DAG:
\_ [root] (ID: scope-id-root)
* 😴 SERVICE-A1
* 😴 SERVICE-A2
* 😴 SERVICE-B
|
|
\_ scope-0 (ID: scope-id-0)
|
|
|\_ scope-1a (ID: scope-id-1a)
| * 😴 SERVICE-C1
| * 😴 SERVICE-C2
| * 😴 SERVICE-D
| * 😴 SERVICE-E
| * 🔁 SERVICE-EAGER-VALUE
| |
| |
| |\_ scope-2a (ID: scope-id-2a)
| | * 😴 SERVICE-LAZY-HEALTH 🏥
| | * 🏭 SERVICE-TRANSIANT-SIMPLE
| |
| |
| \_ scope-2b (ID: scope-id-2b)
| * 😴 SERVICE-LAZY-SHUTDOWN 🙅
|
|
\_ scope-1b (ID: scope-id-1b)
* 😴 SERVICE-F The emoji prefix indicates the service is either Lazy, Eager, or Transiant. The EOL emoji indicates the service implements |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45 +/- ##
==========================================
- Coverage 88.83% 87.56% -1.27%
==========================================
Files 6 23 +17
Lines 430 2043 +1613
==========================================
+ Hits 382 1789 +1407
- Misses 40 225 +185
- Partials 8 29 +21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hello, that's a really great news! Thanks a lot. go get github.com/samber/do@v2-🚀
go: github.com/samber/do@v2-🚀: invalid version: version "v2-🚀" invalid: disallowed version string workaround: |
It would be nice to provide context o healthcheck and shutdown. |
@danilobuerger can you elaborate on your use case? |
Sure, I want to provide a context to be able to use cancellation. |
My last workaround don't work anymore. I've followed this guide https://github.com/samber/do/blob/v2-%F0%9F%9A%80/MIGRATION-V1-TO-V2.md and also the v2 readme : https://github.com/samber/do/blob/v2-%F0%9F%9A%80/README.md |
I renamed the package Adding an emoji in the branch name was definitely a bad idea 😆 |
Not your fault, |
@samber, Since I've designed the ShutdownOnSignals* function to accommodate any signals, we've maintained the I therefore propose deleting What do you think about ? I feel that they are redundant |
One thing I noticed is that the pattern of
Later this fails:
|
@danilobuerger v2 will make it possible to respect this pattern: do.As[*engineServiceImplem, EngineService](injector)
// or
do.InvokeAs[EngineService](injector) See the function comments for the full explanation. |
v2 initial commit
We need to push this PR forward. I created a list of issues that must be addressed before v2 release: Design:
Bugs: Tasks/Features:
Doc: |
Hello @samber, Healthcheck not working properly when calling Seems to work as expected when it's called from my main thread and not from my API (in my main.go for exemple) but this, not working func (a API) GetHealthcheck(_ context.Context, _ openapi.GetHealthcheckRequestObject) (openapi.GetHealthcheckResponseObject, error) {
err := do.DefaultRootScope.HealthCheck()
// never reached
return openapi.GetHealthcheck200JSONResponse{}, nil
} |
…e from an unexecpted type Fixes #80
Hi there 👋,
Over the past 18 months, many of you reported bugs or provided valuable feedback on various aspects of this project, such as error handling, debugging, invocation API, documentation, and more... Thanks for your contributions! 🙌
Work on this library has provided me with significant learning opportunities and now I believe it's time to advance this project further.
Most of the work for v2 has been done already. I'm targeting the end of January for a release. It will depend on additional requirements.
Scope
This milestone will lead to major improvement: Scope.
A
Scope
was previously referred to as anInjector
and can be viewed as a module of an application, with restricted visibility. I advocate for each project possessing aRootScope
for common code, and shifting business logic to dedicatedScopes
.The
Scopes
are structured with a parent (RootScope
or otherScope
), numerousServices
, and potentially a few childrenScopes
as well.RootScope
owns options and is the onlyScope
that supports cloning.Services
from aScope
can invokeServices
available locally or in parentScopes
. Therefore, a singleService
can be instantiated many times in different branches of the Scope tree, without conflict.Scope
will be almost invisible to developers: services will keep usingInjector
API without awareness of the underlying implementation, whether it's aRootScope
,Scope
orVirtualScope
.A chain of
Service
invocation will instantiate manyVirtualScope
, in order to track dependency cycles.A debugging toolchain has been added to illustrate the service dependency chain and Scope tree.
Checklist
The library has been almost entirely recoded, but most of do@v1 API has been preserved (see breaking changes below).
Providers
-> transformed into Goerror
Service
invocation (not visible to developers for now)// @TODO
in the code/v2
suffix (and everywhere in the doc)To be challenged
Service
invocation based on Go field tags (discussed in [proposal] Auto magically inject services #28)Service
aliasing (discussed in Is there an equivalent to dig.As() ? #41 & Anonymous Invocation #25)Healthcheck and shutdown timeout-> passcontext.WithTimeout(10*time.Second)
insteadslog
as logger (breaking change)Export of service DAG to dot files?More existing issues might be added to the v2 milestone.
Documentation
Testing
Code coverage has been improved compared to v1. 😍
// @TODO
in xxx_test.go filesCoverage:
Breaking changes
Injector
struct turned into an interface 😕ListProvidedServices
andListInvokedServices
now return 2do.Edge
arrays.*mypkg.MyService
->*github.com/samber/example.MyService
.injector.ShutdownOnSignals
andinjector.ShutdownOnSIGTERM
now return (os.Signal, error)If you consider the API must be improved, please write a comment on this issue. No breaking change will be done in v2 minor releases. And I hope v2 is going to be the last major version.