You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
},
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!
The text was updated successfully, but these errors were encountered:
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
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
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)
},
})`
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!
The text was updated successfully, but these errors were encountered: