dig icon indicating copy to clipboard operation
dig copied to clipboard

question. Reinitialization provide

Open LazarenkoA opened this issue 2 years ago • 0 comments

hello. I have such a code

container.Provide(func(clientCfg *config.Ignite) database.Db {
		ignite, err := database.NewIgnite(ctx, clientCfg)
		if err != nil {
			logger.Error(fmt.Errorf("container provide error: %w", err))
			return nil
		} else {
			return ignite
		}
	})

if the database is not available at the time of initialization, further calls will return nil

container.Invoke(func(ignite database.Db) error {
      //....
})

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 to container.Provide again?

LazarenkoA avatar Aug 02 '22 09:08 LazarenkoA