| I've always have my handlers individually set as a struct each with a method to handle the route/request. type CreateUser struct { store storage.Store
cache caching.Cache
logger logging.Logger
pub events.Publisher
// etc
}func (op CreateUser) ServeHTTP(ctx, req, rw) {} // or if you have custom handlers func (op CreateUser) ServeHTTP(ctx, input) (output, error) {} And in my main.go, or where I set up my dependencies, I create each operation, passing it its specific dependencies. I love that because I can keep all the helper methods for that specific operation/handler on that specific struct as private methods. It does get tedious when you have one operation needing another, as you might start passing these around or you extract that into its own package/service. |
Whether all the deps are in the method receiver (the parent struct) or in a struct that's a param; it's all just more indirection to hide all the "stuff" that we need cause we think it's ugly. I dream of a world where we don't do that.