Fork me on GitHub
#component
<
2017-01-14
>
potetm16:01:55

@dhruv1 So here's a long-winded answer

potetm16:01:59

The question I always ask about any tool is: What value does it provide me in this situation?

potetm16:01:41

For Component, the short answer is: It provides dependency injection and lifecycle management.

potetm16:01:49

Lifecycle management is obvious, and it doesn't appear that's your primary concern. (Though I will point out that you could create a resource pool for accessing App-B, and then you would need lifecycle management. This isn't necessarily a good idea, but it's not necessarily a poor one either.)

potetm16:01:42

The main benefit of dependency injection is: Flexibility.

potetm16:01:31

You can dynamically configure how an interaction will occur at runtime.

potetm16:01:49

So back to your scenario:

potetm16:01:59

Idea1: You've created a component that, I'm assuming, implements some protocol, and that can be swapped out with another implementation at any time.

potetm16:01:00

Idea2: You've created an implementation-dependent interaction. My-App now must know 1) there exists a string that is a URL to App-B, and 2) that string is contained in an atom.

potetm16:01:14

My take is: If you're going to use a dependency injection scheme, make sure you're getting the full benefit from it. As far as I can tell Idea1 provides more flexibility than Idea2.

potetm16:01:39

That's not to say that you must use a dependency injection scheme. Some apps don't warrant that level of flexibility.

potetm16:01:58

And I'm not sure what your use-case is.

potetm16:01:22

But, if you don't need that level of flexibility, I would do the absolute easiest thing: (defonce url "http://...")

potetm16:01:50

I should note that, in a professional setting, I would always opt for dependency injection. Most professional-grade applications have such a long lifespan that flexibility is key to longterm success.

potetm16:01:13

One last observation: For Idea1, you don't seem to need lifecycle management at all as it stands. I would just construct the record with a url (map->App-B {:url "http://..."}) and then mark it as a dependency of My-App. I don't see what benefit associng/dissocing the url provides.