Skip to content
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

v2: Feature Request - expose a method for add lifecycle hook #58

Closed
kcmvp opened this issue Feb 22, 2024 · 2 comments
Closed

v2: Feature Request - expose a method for add lifecycle hook #58

kcmvp opened this issue Feb 22, 2024 · 2 comments

Comments

@kcmvp
Copy link

kcmvp commented Feb 22, 2024

right now life cycle hook can only be set when build a container as below
`injector := do.NewWithOpts(&do.InjectorOpts{
HookAfterRegistration: func(injector *do.Injector, serviceName string) {
fmt.Printf("Service registered: %s\n", serviceName)
},
HookAfterShutdown: func(injector *do.Injector, serviceName string) {
fmt.Printf("Service stopped: %s\n", serviceName)
},

Logf: func(format string, args ...any) {
    log.Printf(format, args...)
},

})`

my case is that I am using do as DI container build some basic infra in the group for other projects. it's obvious that other teams(projects) also need hooks for project specific design. I export the DI but they can not register hook.

proposal:
if HookAfterRegistration and HookAfterShutdown are slcie of functions and di expose a new method to add a new hook method then it will work in my case

of course there is gotcha: this new added method which for adding hook will throw error when the DI is not emtpy

thank you!

@samber samber modified the milestones: v2.1, v2 May 5, 2024
@samber
Copy link
Owner

samber commented May 5, 2024

I agree.

Let's change that before v2 release. A slice of hooks might be a breaking change in container options.

@samber samber removed this from the v2 milestone May 5, 2024
@samber
Copy link
Owner

samber commented May 5, 2024

Closing your ticket in favor of #70 + #71 + #72.

@samber samber closed this as completed May 5, 2024
@samber samber changed the title v2: Feature Request - expose a method for add lifecycle hook Expose a method for adding/removing lifecycle hook at runtime May 5, 2024
@samber samber changed the title Expose a method for adding/removing lifecycle hook at runtime v2: Feature Request - expose a method for add lifecycle hook May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants