question. Reinitialization provide #357
Unanswered
LazarenkoA
asked this question in
Q&A
Replies: 1 comment
-
The container can't just ignore You could use value groups to do something similar to what you wanted to do. type DBResult struct {
dig.Out
db database.Db `group:"db"`
}
// somewhere in your code invokes this code many times
container.Provide(func(clientCfg *config.Ignite) DBResult {
ignite, err := database.NewIgnite(ctx, clientCfg)
if err != nil {
logger.Error(fmt.Errorf("container provide error: %w", err))
return DBResult{
db: nil
}
} else {
return DBResult{ db: ignite }
}
}) You can then consume this as a list of Dbs that you can iterate and ignore nils:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hello. I have such a code
if the database is not available at the time of initialization, further calls will return nil
is it possible to make it so that when an error occurs
atabase.NewIgnite(ctx, clientCfg)
the container didn't remember the response, but the code went tocontainer.Provide
again?Beta Was this translation helpful? Give feedback.
All reactions