I am not sure yet how to change the code to explain what I mean.
The issue I see, and let me know if I misunderstood something, is the
fact that you have to tell from which module you take your elements.
In the IoCs I know from Java, what you should tell is what you want
rather than from where.
For example,
If you have all your services that depend on a logging service, then I
would like each component to be able to say "I want the logging
service" without taking care of the source. It could be a file logger,
a db logger or a System.out logger.
I think my issue is that I am use to get the instances from the
context and therefore I am use to see the context doing the wiring but
it seems here the modules are doing it.
My approach right now is the following:
I define together a Component + Module + Trait + Implementation trait
On each module I compose them with the components they need so it is
also very easy to understand what is going on.
But the issue with this approach is that it is impossible to tell the
module to use another implementation. For example, I want the context
to inject TestLogger instead of DBLogger during my tests. But because
I use the components I don't see how to do that efficiently.
Again I love the components idea because it makes it very clear what
is being used. But I fail to see how to make it modular as well.
Now that I think about it, tell me if I am right. What I should do is
to have two main modules:
Prod and Dev
Then for each Service I create two Components, one for prod and one
for dev. and then in my context, I can map which component I want and
I can mock whatever I want. Also, this way I can decide to take
ServiceA from Prod and ServiceB from Dev or both from Dev etc etc.
I think my issue was the concept of Module. I will try what I just
explained and I'll let you know.
Please tell me what you think about the idea.