Fork me on GitHub
#pedestal
<
2016-10-25
>
tetriscodes22:10:56

Is it counterproductive to make to try and make pedestal route handlers components?

tetriscodes22:10:19

I’m wanting to make a component that can have a database and mqtt client passed in and if specific HTTP routes get hit, it can write to the database and then put a message on an mqtt channel

tetriscodes22:10:40

(def routes (clojure.set/union #{} foo/routes-with-deps-injected))

donaldball22:10:21

I have one router component that builds the route handlers, passing in the required components

donaldball22:10:26

I have thought about going the next step and having each router handler be its own component and take advantage of the component machinery for dependency graphs, but it felt like too much work for too little payoff in my case

tetriscodes22:10:10

Do you have a snippet?

tetriscodes22:10:50

Do you have your routes nested in a subsystem that gets built on start?

christianromney23:10:57

@tetriscodes have a look at this code https://github.com/pointslope/elements/blob/master/src/pointslope/elements/pedestal.clj#L68-L95 The idea is that any components that the Pedestal component depends on are automatically added to the request map by the using-component interceptor.

christianromney23:10:17

if this is my system definition:

christianromney23:10:09

you can see that the Pedestal component depends on :config

christianromney23:10:29

if I then add the interceptor (using-component :config) to one of my routes, then the handler for that route will find the :config key on the request map with a reference to the configurator component

christianromney23:10:21

using this scheme you can expose any component to your handlers (via the request map) simply by making the pedestal component depend on it.

christianromney23:10:05

this is not "the one true way" to do what you want, but it is "a way" to do so...

tetriscodes23:10:13

@christianromney thank you. I will take a look