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

Singleton's are created twice when resolver returns (T, error) #37

Closed
Place1 opened this issue Apr 7, 2022 · 2 comments · Fixed by #38
Closed

Singleton's are created twice when resolver returns (T, error) #37

Place1 opened this issue Apr 7, 2022 · 2 comments · Fixed by #38
Assignees
Labels
bug Something isn't working

Comments

@Place1
Copy link
Contributor

Place1 commented Apr 7, 2022

i've added some example code below and i've found that the singleton is created twice.

c := container.New()

c.Singleton(func() (ExampleService, error) {
	fmt.Println("singleton created")
	return CreateExampleService()
})

the issue only occurs because the resolver function returns a 2-tuple of (ExampleService, error)

the issue is happening because of the invoke call happening in this loop (I think) https://github.com/golobby/container/blob/master/container.go#L101

miladrahimi added a commit that referenced this issue Apr 7, 2022
miladrahimi added a commit that referenced this issue Apr 7, 2022
Fix issue #37
@miladrahimi miladrahimi self-assigned this Apr 7, 2022
@miladrahimi miladrahimi added the bug Something isn't working label Apr 7, 2022
@miladrahimi miladrahimi linked a pull request Apr 7, 2022 that will close this issue
@miladrahimi
Copy link
Member

Thanks @Place1 for reporting the bug.
It must be fixed on: https://github.com/golobby/container/releases/tag/v3.1.7

@Place1
Copy link
Contributor Author

Place1 commented Apr 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants