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

Support the ability to chain containers (to form scopes) #33

Closed
chirino opened this issue Jun 11, 2021 · 3 comments
Closed

Support the ability to chain containers (to form scopes) #33

chirino opened this issue Jun 11, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@chirino
Copy link
Contributor

chirino commented Jun 11, 2021

It would be nice if you could auto resolve from another container. Example:

	type Message string
	parent, _ := di.New(di.ProvideValue(Message("Hello from parent")))

	child1, _ := di.New(di.Chain(parent))
	child1.Invoke(func(m Message) { fmt.Println(m) })

This would let us have common injection providers in a parent, but still have some child Containers that can inject some variations. Some DI systems call these DI scopes I think.

@defval
Copy link
Owner

defval commented Jun 11, 2021

Hi, @chirino 👋 Thanks for your interest!

I have heard about scopes in DI containers and seen several implementations. But in my practice, I have not encountered a real need to separate components into several containers, especially in Go applications, which are primarily small. I think that scopes are necessary for large codebases with many modules, which components must be isolated from each other.

Maybe you have a real-life example where this functionality would be helpful? We could discuss it :)

@defval defval added enhancement New feature or request under discussion labels Jun 11, 2021
@chirino
Copy link
Contributor Author

chirino commented Jun 12, 2021

We have a case where we support updating the configuration of the server, when the reconfiguration occurs we need to recreate all the services as even the di.Options can change in the child container.

Right now we are pulling objects out of the parent Container and manually putting it in the new child container. It works, but it's not beautiful.

@defval
Copy link
Owner

defval commented Jun 24, 2021

@chirino Functional released. Thanks a lot!

https://github.com/goava/di/releases/tag/v1.10.0

@defval defval closed this as completed Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants