You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the container in this package if I register a resolver for a singleton where it could conditionally fail based on some expectation:
container.Singleton(func() (*Foo, error) {
ifexpectationsAreMet {
returnNewFoo("test"), nil
} else {
returnnil, errors.New("cannot create this type right now")
}
})
Then when the caller attempts to re-resolve the type the cached nil value is returned instead of the resolver trying again.
varinstance*Fooerr:=container.Resolve(&instance) // Resolution can fail here if external expectation is not metiferr!=nil {
// Perform some bootstrapping to meeting required expectationexternal.MeetExpectation()
// Try to resolve the type again after expectations are meterr=container.Resolve(&instance) // Resolver should try again now that expectation has been met.
}
Expected
The registered singleton resolver should run again since the original resolution failed and return an error
Actual
The nil value is stored as the concrete value for the singleton and is returned on subsequent Resolve(...) calls.
The text was updated successfully, but these errors were encountered:
Description
Singleton resolvers that return error during resolution should not cache the concrete instance
Steps to Reproduce
Given the following Go struct
When using the container in this package if I register a resolver for a singleton where it could conditionally fail based on some expectation:
Then when the caller attempts to re-resolve the type the cached
nil
value is returned instead of the resolver trying again.Expected
The registered singleton resolver should run again since the original resolution failed and return an error
Actual
The
nil
value is stored as the concrete value for the singleton and is returned on subsequentResolve(...)
calls.The text was updated successfully, but these errors were encountered: