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: add lifecycle interface support #61

Open
kcmvp opened this issue Feb 24, 2024 · 2 comments
Open

V2 Feature Request: add lifecycle interface support #61

kcmvp opened this issue Feb 24, 2024 · 2 comments
Milestone

Comments

@kcmvp
Copy link

kcmvp commented Feb 24, 2024

I have Java background , in springboot there is a interface named InitializingBean this interface give an opportunity to do some one-time initialization. We can introduce similar interface, service implement this interface will call the method automatically once after the service creation.

@samber
Copy link
Owner

samber commented May 5, 2024

I agree. I often add a small svc.init() before the end of my providers.

When would you call this method?

  • calling init() after each service invocation
  • calling all init() after a chain of service invocation

@samber samber added this to the v2.1 milestone May 5, 2024
@kcmvp
Copy link
Author

kcmvp commented May 6, 2024

I think there is a bit difference between init() method and the case I describe. as go init() is package level and too many init method in a package is not a good practice(my opinion). my case is somelike "constructor" behavior, it should be called by the framework right after the service creation. not sure I address the case well or not.

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