Fork me on GitHub
#pedestal
<
2017-05-16
>
jfntn19:05:53

Does anyone have an example of injecting component dependencies into a service handler?

jfntn19:05:36

In ring I used to inject everything in a server component and close over the dependencies when making the routes.

jfntn19:05:58

Not sure that’s the best approach with pedestal since it seems like a good use-case for an interceptor…?

ddeaguiar19:05:49

@jfntn Unfortunately this guide is still pending http://pedestal.io/guides/pedestal-component-handlers-and-dependencies but I think your approach will work

jfntn19:05:43

Yes I saw that, which is why I asked here 🙂

ddeaguiar19:05:05

You can have an interceptor which assoc’s the pedestal component to the context allowing downstream interceptors to pull the requisite dependencies off it

ddeaguiar19:05:51

I’m also working on an alternative implementation for this. I hope to release it soon and update the guide

jfntn19:05:32

Ah I missed those links, thanks

ddeaguiar19:05:08

again this is a work in progress but the idea is that components provide routes. Component-specific routes include interceptors which provide access to dependencies

ddeaguiar19:05:01

Be aware that the usage described there demonstrates a handler accessing dependencies but I’m going to change that to be an interceptor instead

ddeaguiar19:05:39

by making dependencies accessible via the Context, you gain dynamic dependency mgmt which makes testing easier

ddeaguiar19:05:28

But I’ve used the implementation demonstrated in the Elements project with success as well

ddeaguiar19:05:50

FYI, the code in the master branch of the component-pedestal repo was really experimental. The implementation is cute but I don’t think it’s a good idea to decouple components from their usage in interceptors/handlers.

jfntn19:05:05

That’s nice, had a similar RouteProvider protocol with our ring version and I liked it, but I’m not sure how if I like having per-route component injectors, I think I’d rather always add the union of all deps to the context and forget about it

ddeaguiar19:05:11

Then the approach implemented by Elements, which is based on Stuart Sierra’s component-pedestal exploration, is for you.

jfntn20:05:22

Looks good to me, thanks @ddeaguiar !

kenny23:05:57

What is the recommended way of handling parse failures from io.pedestal.http.body-params/body-params? i.e. When a request contains invalid JSON causing Cheshire to fail parsing it. I see two options: 1. Write my own version of the body-params interceptor that wraps the call to parse-content-type in a try/catch. 2. Add an error interceptor to the interceptor chain that looks for parse failure exceptions and attaches a :status 400 to the :response. I don't really like option 2 because it forces you to have to remember that if you use the body-params interceptor you must also use the error interceptor. I'm just wondering what you guys typically do.