im-kulikov/helium

Is there a way to understand why certain services have not started?

OrangeFlag opened this issue · 8 comments

Is your feature request related to a problem? Please describe.
I am in pain when I wrote a new service, added its module, but it does not start for some unknown reason.
Usually the reason lies in some dependencies that have not arrived, but there is no way to find out, because dig instance is hidden in implementation

Describe the solution you'd like
At least a way to call dig.Visualize

Describe alternatives you've considered
Maybe access to the dig container itself

Additional context

@OrangeFlag Can you provide an example of module / service to reproduce a problem?

Have you tried examples from README?

Okay, I figured it out. I had to return the service.Service interface from my constructor for this to work

Two ways that work:

var Module = module.Module{
	{Constructor: NewMock2, Options: []dig.ProvideOption{dig.Group("services")}},
}
func NewMock2() (service.Service) {
	return &Mock2{}
}
var Module = module.Module{
	{Constructor: NewMock2},
}

type OutParams struct {
	dig.Out
	Service service.Service `group:"services"`
}

func NewMock2() OutParams {
	return OutParams{Service: &Mock2{}}
}

First observation:
It is still not clear how to debug helium in general.
Perhaps you should enable visualization or add some strict tag for modules, which would stop the application with an error, saying which dependency is missing or something like that.

Second observation:
README gives not quite correct examples (?)

var _ = module.Module{
    {Constructor: NewSingleService, Options: dig.Group("services")}, // <-- this
}

Correct way:

var _ = module.Module{
	{Constructor: NewSingleService, Options: []dig.ProvideOption{dig.Group("services")}},
}

Second observation:
README gives not quite correct examples (?)

var _ = module.Module{
    {Constructor: NewSingleService, Options: dig.Group("services")}, // <-- this
}

Correct way:

var _ = module.Module{
	{Constructor: NewSingleService, Options: []dig.ProvideOption{dig.Group("services")}},
}

Hmm.. mb problems after latest update of dig, not sure.
Pls, make PR with update of README or wait when I'll do it.

Perhaps you should enable visualization or add some strict tag for modules, which would stop the application with an error, saying which dependency is missing or something like that.

I'm not sure if this would be the correct behavior, because in the case when the developer does not want to use services , Helium should impose such behavior on him.

It is still not clear how to debug helium in general.

I will think about that, if you have some, open new issue.

[]dig.ProvideOption{dig.Group("services")}}

Mb in future we can have something like

package service

import "go.uber.org/dig"

var serviceGroup = []dig.ProvideOption{dig.Group("services")}}

func GroupOption() []dig.ProvideOption { return serviceGroup }

What you think about that?