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

Copy a container #236

Open
jstroem opened this issue Apr 1, 2019 · 3 comments
Open

Copy a container #236

jstroem opened this issue Apr 1, 2019 · 3 comments

Comments

@jstroem
Copy link

jstroem commented Apr 1, 2019

I have e scenario where I want to reuse the snapshot a container from a given point in time and use it many times over and over again.
One primitive that could be used for this is a Copy method that ensures that both the original and the copied container can be used without interfering with each other.

Is this something that could be built in?

@abhinav
Copy link
Collaborator

abhinav commented Apr 5, 2019

Hello! We haven't had a chance to fully evaluate the implications of such a
feature, and on first glance would not be strongly opposed to it.

But first, can you describe the use case a bit more? Wanting to re-use a
container many times suggests you might be using it on the request path which
is something we strongly discourage.

@jstroem
Copy link
Author

jstroem commented Apr 5, 2019

Sure.
In my example I am using the a Dig Container to hold "fixtures" during my go tests.
Some fixtures should be loaded once per go test execution and others once per test.

Let me give you a concrete example:

func setupTestRandomOnce() *rand.Rand {
  return rand.New(rand.NewSource(99))
}

func setupGomockCtrl(t *testing.T, r *rand.Rand) *gomock.Controller {
  return gomock.NewController(t)
}

Here, my setupTestRandomOnce func should only be called once during a go test ./ execution whereas the setupGomockCtrl should be executed on every test.

If I have the possibility to Copy I container, I would be able to setup all the providers that does not relate to *testing.T and then use that as a "Base" to copy every time i run a new test.

I hope that explained my use-case.
Let me know what you think.

@sywhang
Copy link
Contributor

sywhang commented Sep 20, 2022

I do realize this is a pretty old thread, but I'd like to revive this feature request. This is a valid use case, and I'll start tracking this work in our todo list for Dig.

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

No branches or pull requests

3 participants