Allow integrating data into IConfigManager#1259
Conversation
1nf0rmagician
left a comment
There was a problem hiding this comment.
I'm happy with the concept and think it is a nicely limited change!
I already went quite into the details with the review, but please take this not as a being overly picky with the PR. I needed to read it closely for full understanding and when I spotted something I didn't want to forget about it later when you had brought it out of the draft state 😬🤗
| private static string KeyFromAttribute(object config, InjectedConfigAttribute attribute) | ||
| { | ||
| var configKey = attribute.ConfigKey; | ||
| if (attribute.FromProperty) |
There was a problem hiding this comment.
You could throw nice exceptions if someone missconfigured the property name or the property is not a string property. I think currently the behaviour is rather undefined
| return configKey; | ||
| } | ||
|
|
||
| private object GetRootConfigKey(Stack<ExecutorLevel> levels) |
There was a problem hiding this comment.
This should return string shouldn'T it?
| return ValueProviderResult.Skipped; | ||
| } | ||
|
|
||
| private string GetConfigKeyNameCached(Stack<ExecutorLevel> levels) |
There was a problem hiding this comment.
I must admit I do not quite get the caching part in this, maybe a little explanation comment/example comment would help me🙈
There was a problem hiding this comment.
It only stores the config key for an element it has already seen in the dict attached to the stackframe.
This means that if we have nested configuration, you don't have to build the entire path from scratch each time.
There was a problem hiding this comment.
While you have implemented collection handling (as far as i can see) there is no test for this
dbeuchler
left a comment
There was a problem hiding this comment.
I like that implementation! Thanks for that. (just small things from my end: code format, braces, no one liners...).
One thing to think about: Why do you have touched the default ConfigManager? I think this can easily archived by derive from it and provide an additional implementation which the application developer can select if required. Keeps the default implementation as it is and for extended usage, it is possible to use it in application.
Before we merge it to dev and make an release instantly, could we apply this into an application (I don't mean the demo) to test if it behaves as wanted?
Thank you very much :)
That's good idea. I would add a switch to the AddMoryxKernel Extension method that allows opting in to the new behavior, if that's ok with you
That's my plan. That's why it's still in draft. Additionally I intend to add a regression test that takes the ModuleConfigs of the core Modules and checks that, if the IConfiguration is empty, you get the exact same configs. |
Instead of adding options to the extensions, another idea: You can replace registered services with |
|
Isn't it completely optional if I define the Method as Nobody would have to change their code, it's much more discoverable as a hint in the docs and the "new ConfigManager" (not sure on naming yet, or if even needs a new type. Maybe it could just be a different constructor that takes a list of IValueProviders) can be internal. By the way: Is there a reason for the existing ConfigManager being public? In an application we always use it through the IConfigManager interface |
| This can be set in appsettings.json like this: | ||
|
|
||
|
|
||
| You can archive this by adding the following to your appsettings.json |
| return manager; | ||
| } | ||
|
|
||
| // TODO: Consider removing -> Tested by MicrsoftExtensionConfigProviderTests |
There was a problem hiding this comment.
Open todos in this file, if you ask me, I like keeping some integration tests (if they actually test just a littel bit more than the MicrsoftExtensionConfigProviderTests.
There was a problem hiding this comment.
Ok, than I'll remove the TODOs. They test the integrate a little bit
to allow injecting secrets and arbitrary config into the Moryx Configuration System Refactor to ValueProvider and add (failing) test to ensure the secret is not written out to file Rewrite to allow injecting arbitrary config properties from IConfiguration. * Add IContextAwareConfigProvider to keep track of nesting * Implement the new interface in MsExtensionsConfigProvider * Add Tests * Rename MsExtensionsConfigProvider to MicrosoftExtensionConfigProvider and rename test accordingly * Rename InjectedConfigAttribute to ProvidedConfigAttribute * Move tests for integration of the new ConfigProvider into the ConfigManager into ConfigManagerWithConfigProviderTests * Role back changes to ConfigManager so that it behaves as previously by default and add parameter to AddMoryxKernelExtension Method to allow opting in to the new behavior * Add tests for populating Lists using the new Provider and fix the implementation for that case. * Add error logs when we can't bind values for when something goes wrong
a7100a0 to
a2096cc
Compare
Summary
Allow populating ModuleConfigs from IConfiguration entries.
This is our way to allow injecting secrets and configuration from ConfigurationProviders based on Microsoft.Extensions.Configuration into the MORYX IConfigManager.
To properly handle nested configs (an important part of the IConfiguration concept the ValueProviderExecutor has been extended to allow access to context information through the new IContextAwareValueProvider interface.
Linked Issues
CLoses #710
It does not depend on the Password Attribute as mentionend in the Issue, because the Password Attribute still means that the value will be serialized to disk and over the API.
Relevant logs and/or screenshots
Breaking Changes
Checklist for Submitter
Review
Typical tasks
Obsoleteattributes if necessaryClean code