Skip to content

Allow integrating data into IConfigManager#1259

Merged
andreniggemann merged 3 commits into
devfrom
feature/configuration-providers
Jun 18, 2026
Merged

Allow integrating data into IConfigManager#1259
andreniggemann merged 3 commits into
devfrom
feature/configuration-providers

Conversation

@andreniggemann

@andreniggemann andreniggemann commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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

  • I have tested these changes locally
  • I have updated documentation as needed
  • I have added or updated tests as appropriate
  • I have used clear and descriptive commit messages

Review

Typical tasks

  • Merge request is well described
  • Added Obsolete attributes if necessary
  • Critical sections are documented in code
  • Tests available or extended
  • Documentation is created / updated
  • Running in test environment
  • Manual is created / updated
  • Ports to other maintained versions are created

Clean code

  • All unused references are removed
  • Clean code rules are respected with passion (naming, ...)
  • Avoid copy and pasted code snippets

@1nf0rmagician 1nf0rmagician added the enhancement New feature or request label Jun 9, 2026
@1nf0rmagician 1nf0rmagician added this to the Framework 10.x milestone Jun 9, 2026

@1nf0rmagician 1nf0rmagician left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😬🤗

Comment thread src/Moryx/Configuration/ValueProvider/IContextAwareValueProvider.cs Outdated
Comment thread src/Moryx/Configuration/InjectedConfigAttribute.cs Outdated
Comment thread src/Tests/Moryx.Runtime.Kernel.Tests/Configuration/ConfigManagerTests.cs Outdated
Comment thread src/Tests/Moryx.Runtime.Kernel.Tests/Configuration/ConfigManagerTests.cs Outdated
private static string KeyFromAttribute(object config, InjectedConfigAttribute attribute)
{
var configKey = attribute.ConfigKey;
if (attribute.FromProperty)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return string shouldn'T it?

return ValueProviderResult.Skipped;
}

private string GetConfigKeyNameCached(Stack<ExecutorLevel> levels)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit I do not quite get the caching part in this, maybe a little explanation comment/example comment would help me🙈

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you have implemented collection handling (as far as i can see) there is no test for this

@dbeuchler dbeuchler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@andreniggemann

andreniggemann commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

I like that implementation! Thanks for that. (just small things from my end: code format, braces, no one liners...).

Thank you very much :)

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.

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

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?

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.

@dbeuchler

Copy link
Copy Markdown
Member

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

Instead of adding options to the extensions, another idea: You can replace registered services with services.Replace? Maybe a simple hint in the docs and this behavior is fully optional.

@andreniggemann

Copy link
Copy Markdown
Collaborator Author

Isn't it completely optional if I define the Method as AddMoryxKernel(bool configurationIntegration = false)?

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

@andreniggemann andreniggemann marked this pull request as ready for review June 12, 2026 08:55
1nf0rmagician
1nf0rmagician previously approved these changes Jun 12, 2026
Comment on lines +102 to +105
This can be set in appsettings.json like this:


You can archive this by adding the following to your appsettings.json

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little duplicate

return manager;
}

// TODO: Consider removing -> Tested by MicrsoftExtensionConfigProviderTests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, than I'll remove the TODOs. They test the integrate a little bit

Comment thread src/Moryx.Runtime.Kernel/KernelServiceCollectionExtensions.cs
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
@andreniggemann andreniggemann force-pushed the feature/configuration-providers branch from a7100a0 to a2096cc Compare June 18, 2026 10:58
@andreniggemann andreniggemann merged commit 8397774 into dev Jun 18, 2026
7 checks passed
@andreniggemann andreniggemann deleted the feature/configuration-providers branch June 18, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow optional integration of configuration providers in MORYX ConfigurationManager

3 participants