System construction and desctruction only
Once your compnents have been created, they are on their own
i.e. it does not automatically add anything to a request/opartaion
Add something to every request
Create a RingHandlerProvider designed to run just after the web server
Intercept the handler
Add wahtever you like to the request map and call the handler
(defrecord RingBinder []
component /Lifecycle
(start [this] this)
(stop [this] this)
RingHandlerProvider
(handler [this]
(let [ring-handler-provider (find-ring-handler-provider this)
ring-handler (handler ring-handler-provider)
ring-bindings (get-ring-bindings this)]
(fn [req]
(ring-handler (assoc req :params ring-bindings))))))
Update the dependency map
(defn new-system []
(let [system-map (component/system-map
:webserver (new-webserver :port 3000 )
:ring-binder (new-ring-binder )
:router (new-bidi-ring-handler-provider )
:application-layout (new-layout :template " views/layouts/application.html.mustache" )
:web (new-web {:templates
{:index (slurp " resources/views/index.mustache" )}}))]
(component/system-using system-map
(-> {:webserver {:router :router }
:router {:web :web }
:ring-binder {:web :web }}
(interpose-component :webserver :application-layout )
(interpose-component :webserver :ring-binder )))))