 (defn create-context
   {:internal true}
   [^Context ctx]
-  (let [holder (-> (.getRequest ctx)
-                   (hp/maybe-get ContextHolder))]
-    (merge (if holder
-             (.-data ^ContextHolder holder)
-             (build-context ctx))
-           {:route-params (get-route-params ctx)}
-           (get-context-params ctx))))
-
+  (let [^Request req (get-request* ctx)
+        ^ContextHolder holder (reg/maybe-get req ContextHolder)]
+    (if holder
+      (merge (.-data ^ContextHolder holder)
+             {:route-params (get-route-params ctx)}
+             (get-context-params ctx))
+      (let [context (build-context ctx)
+            holder (ContextHolder. context)]
+        (reg/add! req holder)
+        (merge context
+               {:route-params (get-route-params ctx)}
+               (get-context-params ctx))))))

  handler using the `delegate` function. Is a simple
  way to communicate the handlers chain."
  {:internal true :no-doc true}
  [ctx]
  (when-let [dc (-> (get-context* ctx)
                    (hp/maybe-get DelegatedContext))]
    (.-data dc)))

(defn delegate
  "Delegate handling to the next handler in line.

           (hp/on-error reject)
           (hp/then resolve))))))

;; --- Implementation

(defn build-context
  {:internal true}
