Closed suzuki-safie closed 11 months ago
When using third-party types like sql.DB or redis.Client, it is often necessary to create a new type to specify the Shutdown behavior.
type DBWithShutdown sql.DB func (db *DBWithShutdown) Shutdown() error { return db.Close() }
This not only requires defining an additional type but also requires additional type conversions.
My proposal is:
ProvideXXX
Shutdown
WithShutdownFunc
injector := do.New() do.Provide(injector, func(i *do.Injector) { return sql.Open(...) }, do.WithShutdownFunc(func (db *sql.DB) error { return db.Close() })) do.Invoke[*sql.DB](injector) injector.Shutdown()
@samber: Would you have any thoughts?
When using third-party types like sql.DB or redis.Client, it is often necessary to create a new type to specify the Shutdown behavior.
This not only requires defining an additional type but also requires additional type conversions.
My proposal is:
ProvideXXX
, with functional optional patternShutdown
behavior withWithShutdownFunc
option