Generalized implementation of the middleware abstraction
