Closed jozolam closed 11 months ago
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"
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?
Hi there and sorry for the late reply.
It could be fixed by injecting the right type: do.InvokeNamed[int](injector, v)
do.InvokeNamed[int](injector, v)
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
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?