Fork me on GitHub
#duct
<
2020-04-08
>
erwinrooijakkers16:04:26

What is a proper way to provide a different implementation of a boundary in dev versus prod?

weavejester16:04:08

You give the prod and dev implementations different keywords, deriving from the same base.

erwinrooijakkers16:04:33

Is there an example somewhere?

weavejester16:04:21

I can’t think of one off the top of my head. Let me sketch one out for you.

erwinrooijakkers16:04:40

Great I basically have a defprotocol with two implementations

weavejester16:04:03

Okay, so you’d write init-key methods for both of them:

(defmethod ig/init-key ::dev [_ opts]
  (->DevType opts))

(defmethod ig/init-key ::prod [_ opts]
  (->ProdType opts))

weavejester16:04:11

And then in your duct_hierarchy.edn you’d put something like:

{:app.foo/dev [:app/foo]
 :app.foo/prod [:app/foo]}

weavejester16:04:24

So they derive from the same parent.

weavejester16:04:45

Then you put the dev one in your dev profile, and the prod one in your prod profile.

weavejester16:04:03

And refer to it using the parent keyword, e.g. #ig/ref :app/foo.

weavejester16:04:46

That way the reference will choose whichever key (dev or prod) is in your configuration.

erwinrooijakkers19:04:41

Thanks took some time to digest and implement, but works like a charm now

erwinrooijakkers16:04:31

Cannot find an example

erwinrooijakkers16:04:58

So I want a component to depend on an abstraction

erwinrooijakkers16:04:12

And then provide in config what implementation of the abstraction I use