func Middleware(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		requestContext := r.Context()
		for beanID, scope := range scopes {
			if scope != Request {
				continue
			}
			beanInstance := getRequestBeanInstance(requestContext, beanID)
			requestContext = context.WithValue(requestContext, BeanKey(beanID), beanInstance)
			if isCloseable(beanInstance) {
				go func(ctx context.Context, beanInstance interface{}) {
					<-ctx.Done()
					err := beanInstance.(io.Closer).Close()
					if err != nil {
						panic(err)
					}
				}(r.Context(), beanInstance)
			}
		}
		next.ServeHTTP(w, r.WithContext(requestContext))
	})
}
Middleware is a function that can be used with http routers to perform Request-scoped beans injection into the web
request context. If such bean implements io.Closer, it will be attempted to close upon corresponding context
cancellation (but may panic).
package di
import (
	"context"
	"io"
	"net/http"
)
type BeanKey string