Exploring Hierarchical Configurations in Applications #1715
Replies: 2 comments 3 replies
-
Hey @hrstkatomas, thank you so much for bringing up the discussion. It's sort of late in my timezone so I'll provide a proper answer tomorrow, Edit: Ok, it seems I have more time. In order to keep an structured discussion, I'll start here talking about your use case.
I see, at first glance I would probably resolve with
Yeah, I think it's fine. They are just suggestions. My cup of teawould be having a ConfigurationService which probably can be iterated to fetch env vars or config from any other source, but sometimes keeping things simple is the best way to go.
Sure, First I would like to know the reason to not to use |
Beta Was this translation helpful? Give feedback.
-
Now, regarding #954:
Yeah, I get your use case and makes sense for this use case. Unfortunatelly, inversify is so flexible that changing the behavior would lead to some weird behaviors in my humble opinnion. The current beahvior
c.get finds registered bindings at c. If no bindings are found, p bindings are used instead. You're probably wondering what does "if no bindings are found" mean. const parentContainer = new Container();
parentContainer.bind("SHARED").toConstantValue("V1").whenTargetNamed("S1");
const childrenContainer = parentContainer.createChild();
childrenContainer.bind("SHARED").toConstantValue("V2").whenTargetNamed("S2");
// An error is thrown
childrenContainer.getNamed("SHARED", "S1") Well, Should we change this behavior?I don't think so. A child container is supposed to override service bindings. Two possible behaviors come to my mind Provide fine grained overridesI am aware A child container could always use both parent and their own bindingsI believe this would be really confusing given the current behavior and there would be no way to replace parent bindings by child bindings. Of course, I'm open to talk about this and any other proposal. |
Beta Was this translation helpful? Give feedback.
-
So I was exploring the concept of providing my application with config values using hierarchical containers. It was inspired by the hierarchy of containers Angular has.
Here's the structure I'm considering:
Each container can specify configuration for different abstraction levels:
Feature needed some platform-specific configuration? Container hierarchy got you covered.
Also, the idea seemed fairly flexible because I could override any configuration at any level if needed.
The named binding seemed like a good idea. I could hide my config values under one key:
When I tried it I encountered this issue #954
There are ways around this, but I am unsure I went down the right path.
I guess I violated the "Avoid the injection of data, as opposed to behaviour" principle mentioned in the good practices section of the documentation.
Is there a way to achieve this kind of configuration flexibility while providing an abstraction of the configuration? I would appreciate any suggestions on how to approach this. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions