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

Warm up the container #35

Closed
jozolam opened this issue May 23, 2023 · 1 comment
Closed

Warm up the container #35

jozolam opened this issue May 23, 2023 · 1 comment

Comments

@jozolam
Copy link

jozolam commented May 23, 2023

Hello, I would like to test that all services are wired correctly inside my DIC and also warm up when booting the app.
I would like to do something like this

func TestAllServicesInDI(t *testing.T) {
	injector := do.New()
	do.ProvideNamedValue(injector, "first", 1)
	do.ProvideNamedValue(injector, "second", 2)
	do.ProvideNamedValue(injector, "third", 3)
	do.ProvideNamedValue(injector, "string", "Hello World!")

	for _, v := range injector.ListProvidedServices() {
		_, err := do.InvokeNamed[any](injector, v)
		assert.NilError(t, err)
	}
}

It will fail with assertion failed: error is not nil: DI: could not find service "third", available services: "third", "string", "first", "second"

The easiest way how to accomplish this would be to add InvokeNamedUntyped(i, name) or something that would return any but invoke the service. WDYT?

@samber
Copy link
Owner

samber commented Oct 30, 2023

Hi there and sorry for the late reply.

It could be fixed by injecting the right type: do.InvokeNamed[int](injector, v)

@samber samber closed this as completed Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants