Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handler and transient dependency middleware #126

Open
zalky opened this issue Feb 12, 2018 · 1 comment
Open

Handler and transient dependency middleware #126

zalky opened this issue Feb 12, 2018 · 1 comment

Comments

@zalky
Copy link

zalky commented Feb 12, 2018

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.

@danielsz
Copy link
Owner

Yes, that sounds like a good idea. Thank for the PR.
I'll take a closer look as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants