хочу абстрагироваться от реализации сервис контейнера
import (
"go.uber.org/dig"
)
type Application struct {
container Container
}
func (app *Application) Run() {
err := app.container.Invoke(func(config Config) {
fmt.Println(config.GetHost())
})
if err != nil {
panic(err)
}
}
type Container interface {
Provide(constructor interface{}, opts ...interface{}) error
Invoke(function interface{}, opts ...interface{}) error
}
func NewApplication(container Container) (*Application, error) {
return &Application{
container: container,
}, nil
}
func BuildContainer() (*dig.Container, error) {
container := dig.New()
err := container.Provide(interface{}(NewConfig()))
if err != nil {
return nil, err
}
return container, nil
}
func main() {
container, err := BuildContainer()
if err != nil {
panic(err)
}
app, err := NewApplication(container)
if err != nil {
panic(err)
}
app.Run()
}
но выпадает ошибка:
#13 0.387 cmd/app/main.go:26:40: cannot use container (type *dig.Container) as type application.Container in argument to application.NewApplication:
#13 0.387 *dig.Container does not implement application.Container (wrong type for Invoke method)
#13 0.387 have Invoke(interface {}, ...dig.InvokeOption) error
#13 0.387 want Invoke(interface {}, ...interface {}) error
как правильно определить интерфейс?