weavejester / ring-jetty-component

A component for the standard Ring Jetty adapter
32 stars 3 forks source link

Inject jetty component into request map #5

Closed lukaszkorecki closed 7 years ago

lukaszkorecki commented 7 years ago

This injects current component into the request map - thus exposing web server component's dependencies to the request handler. My understanding is that component ensures that dependencies are started before the component which depends on them.

For minimal use cases creating a handler component might be a bit too much. Not sure if this approach is the best but for a case where handler fn depends on one component (like a connection pool) all seems to be working fine.

Let me know what you think 👍

weavejester commented 7 years ago

Creating a handler component is still, I think, the right way to go about this.

(defrecord HandlerComponent [build-handler]
  component/Lifecycle
  (start [component]
    (if (:handler component)
      component
      (assoc component :handler (build-handler component))))
  (stop [component]
    (dissoc component :handler)))

It isn't much code and can be factored out into another library. It's also a much better way of handling dependencies than trying to push them through the request map.

lukaszkorecki commented 7 years ago

Got it 👍

Also, in most situations simple cases stop being simple very fast ;-)