'could not build arguments for function
I am trying to build go application using DI but since I just started to learn how to do this I am facing problem as below
"could not build arguments for function "github.com/pharmeasy/kite/service/handlers".CreateExperiment.func1 (/Users/sahilpaudel/Documents/PharmEasy/Go/kite/service/handlers/experiment.go:62): failed to build *repository.ExperimentRepository: missing dependencies for function "github.com/pharmeasy/kite/core/dao/repository".NewExperimentRepository (/Users/sahilpaudel/Documents/PharmEasy/Go/kite/core/dao/repository/experiment.go:16): missing type: *string"
repository looks like this
type ExperimentRepository struct {
dbName *string
}
// NewExperimentRepository returns new ExperimentDao
func NewExperimentRepository(dbName *string) *ExperimentRepository {
return &ExperimentRepository{ dbName: dbName }
}
func (expRepo *ExperimentRepository) Create(experiment *models.Experiment) error {
return nil
}
DI looks like this
func buildContainer() *dig.Container {
container := dig.New()
_ = container.Provide(config.NewConfig)
_ = container.Provide(database.GetInstance)
_ = container.Provide(repository.NewExperimentRepository)
return container
}
And I am trying to use it here as
di := container.GetInstance()
err = di.Invoke(func(experimentRepo *repository.ExperimentRepository) {
err := experimentRepo.Create(&experiment)
if err != nil {
utils.RespondError(res, err, http.StatusInternalServerError)
return
}
})
Stucks since morning and but couldn't figure out whats the issue here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
