Skip to content

Handler and transient dependency middleware #126

Open
@zalky

Description

@zalky

I have a component that has its own middleware:

(defrecord SenteHandler [respond-to middleware]
  component/Lifecycle
  (start [component]
    (assoc component :handler
      (if middleware
        ((apply comp (reverse middleware)) respond-to)
        respond-to)))

  (stop [component]
    (dissoc component :handler)))

I am also using the system.component.handler/Handler component. My SenteHandler is a transient dependency of the system.components.handler/Handler:

{...
 :sente             [:sente-handler]
 :private-endpoints [:sente]
 :handler           [:public-endpoints
                     :private-endpoints
                     :middleware]}

When :middleware in SenteHandler is nil, Handler is throwing a NullPointerException on L37. If I change :middleware key in SenteHandler to anything else, such as :mw, Handler does not throw an exception. Handler seems to be searching for middleware in transient dependencies by checking for the :middleware key.

While this is fairly easy to work around, would it make things more robust to check the type of the component instead or checking for keywords that are not namespaced? Something like (instance? Middleware component)? I've thrown together a simple PR and it seems to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions