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 support for scopes #249

Closed
mfateev opened this issue Aug 12, 2019 · 2 comments
Closed

Add support for scopes #249

mfateev opened this issue Aug 12, 2019 · 2 comments

Comments

@mfateev
Copy link

mfateev commented Aug 12, 2019

The basic idea is similar to the Spring one.

The strawman proposal is to support Container new that takes a parent container:

rootScope := dig.New()
rootScope.Provide(...)
// Execute per request
requestScope := rootScope.New()
requestScope.Provide(...)
requestScope.Invoke(...)

In the above example the requestScope container can use objects from rootScope as inputs.

Another option is to configure providers once and be able to reuse them, but it would require changing API to separate out the Container form ContainerConfig (which would solve the copy issue as well). Something like:

c := dig.New()
c.Provide(...)
g1 := c.NewObjectGraph()
g.Invoke(...)
g2 := c.NewObjectGraph()
@glibsm
Copy link
Collaborator

glibsm commented Aug 12, 2019

It sounds similar to what was proposed here as fx.Module uber-go/fx#653 (comment)

There are also some mentions of sub-graphs, and modifying graphs for things like unit testing.

Are you looking to get only this proposal approved, or also do the PR for it?

@mfateev
Copy link
Author

mfateev commented Aug 12, 2019

uber-go/fx#653 looks like what I want. Resolving as duplicate

@mfateev mfateev closed this as completed Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants