Added
whyor.Cleanup, a func(context.Context) error type for explicit shutdown.
- Providers and injectors may return context-aware cleanup functions. Legacy
func() provider cleanups can be mixed into a modern injector.
- Modern cleanup calls execute in reverse order and aggregate errors with
errors.Join. Closer errors are preserved in modern injectors.
- Failed initialization aggregates its error with errors from acquired cleanups.
Rollback preserves injector context values through context.WithoutCancel,
or uses context.Background() when no context parameter exists.
- Lifecycle examples and tests covering shutdown context propagation, canceled
acquisition contexts, mixed cleanups, rollback and empty cleanup functions.
Upgrade notes
- Existing
func() cleanup declarations retain their behavior. Modern provider
cleanups require an injector returning whyor.Cleanup or the equivalent
function signature; they cannot silently lose errors in a legacy injector.
- Shutdown context is supplied by the caller and passed unchanged. Rollback
strips acquisition cancellation and deadlines; no timeout is added. Cleanup
implementations must bound blocking operations themselves.
- Cleanups are cooperative, synchronous and not automatically idempotent.
- Requires Go 1.27.1+. JSON graph schema stays at version
1.
go install github.com/Medzoner/whyor/cmd/whyor@v0.10.0
go get github.com/Medzoner/whyor@v0.10.0
whyor gen ./...
go test ./...