The cacheroach project uses Wire, which provides compile-time dependency injection for Go. Wire takes care of handling both set-up and tear-down of singleton service objects within cacheroach.
- Each package should expose a public
ProviderSet
namedSet
. - If provider functions are used to construct a stateful object, it should be in a ready-to-use state when it is returned from the provider. Stateful objects should return a cleanup function from the provider which will release any external resources.
- Packages that need to test injected types should define an unexported, minimally-scoped "test rig" injector type.