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

add close method #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add close method #56

wants to merge 2 commits into from

Conversation

leijux
Copy link

@leijux leijux commented Dec 14, 2023

close Calls the close method on all singleton instances within the container.

@miladrahimi
Copy link
Member

Do you believe it's truly the responsibility of the IOC container to handle the closure of services?

@leijux
Copy link
Author

leijux commented Dec 16, 2023

Do you believe it's truly the responsibility of the IOC container to handle the closure of services?

I tried to close all instances with Close(c container.Container), but concrete.isSingleton and concrete.make are unexported fields and methods.

Thanks for your help!

@leijux
Copy link
Author

leijux commented Dec 16, 2023

I think it is necessary to condition the close method.

  1. have no impact on existing functions and methods
  2. Convenient to close db like services

@miladrahimi
Copy link
Member

I know that close is not a special method, and I don't understand why all objects should have such a method. Could you explain more about it?

@leijux
Copy link
Author

leijux commented Dec 22, 2023

I know that close is not a special method, and I don't understand why all objects should have such a method. Could you explain more about it?

Although 'close' is not a special method, some objects conventionally use it to release resources such as databases or files.

Therefore, if the Singleton has a 'close' method, it should be called to release the resource.

v := reflect.ValueOf(instance)
mm := v.MethodByName("Close")
if mm.IsValid() {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants