Skip to content

Allow optional integration of configuration providers#894

Draft
jsonBackup wants to merge 1 commit intoPHOENIXCONTACT:futurefrom
jsonBackup:feature/configuration-providers
Draft

Allow optional integration of configuration providers#894
jsonBackup wants to merge 1 commit intoPHOENIXCONTACT:futurefrom
jsonBackup:feature/configuration-providers

Conversation

@jsonBackup
Copy link
Member

@1nf0rmagician 1nf0rmagician added this to the Framework 8.x milestone Dec 7, 2025
@1nf0rmagician 1nf0rmagician added the enhancement New feature or request label Dec 7, 2025
Copy link
Member

@1nf0rmagician 1nf0rmagician left a comment

Choose a reason for hiding this comment

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

First draft looks promising to me 👍 The following point you could consider next:

  • Add/Modify documentation accordingly
  • Add a short tutorial on how to populate config values e.g. in the MQTT or OPC UA Driver config from environment variables
  • Add code or a seperate ticket for nested properties in objects in the config
  • Clean up some of the code, test names, comments, etc.

I think the limitation to string properties could only be overcome with the implicit config population and since you only consider password properties there they will need to be of type string to 😅 But I think you could split this up into a separate issue, if you already have an idea on how to solve this, keeping this change limited to string properties would be alright for me.

public ModuleController(IModuleContainerFactory containerFactory, IConfigManager configManager, ILoggerFactory loggerFactory, IDbContextManager contextManager)
: base(containerFactory, configManager, loggerFactory)
{
// first tests:
Copy link
Member

Choose a reason for hiding this comment

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

Nice that this works, but I think it should not be the focus of this pr 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Remember to remove before merge


// NEW: hook up IConfiguration from the host
var configuration = serviceProvider.GetService<IConfiguration>();
if (configuration != null)
Copy link
Member

Choose a reason for hiding this comment

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

As the property is nullable no need for the extra check, is it?

Copy link
Member

Choose a reason for hiding this comment

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

isn't the property filled by the service collection?!

config = CreateConfig(confType, ConfigState.Generated, "Config file not found! Running on default values.");

// Defaults & shared configs
ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddProviders(ValueProviders));
Copy link
Member

Choose a reason for hiding this comment

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

What does this line do?

Copy link
Member

Choose a reason for hiding this comment

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

Executes the value provider (e.g- default values...) I wonder why this was not applied before?

_sharedProvider = new SharedConfigProvider(this);
}

protected virtual void ApplyConfigurationProviders(object config)
Copy link
Member

Choose a reason for hiding this comment

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

Can't you already limit this to ConfigBase?

if (string.IsNullOrWhiteSpace(candidateKey))
continue;

var providerValue = Configuration[candidateKey!];
Copy link
Member

Choose a reason for hiding this comment

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

What happens here if multiple providers are available?

if (!string.IsNullOrEmpty(providerValue))
{
// Replace placeholder with the actual secret
prop.SetValue(config, providerValue);
Copy link
Member

Choose a reason for hiding this comment

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

Add logging that a variable was used from a conifguration provider, if available from which configuration provider. But do NOT log the variable value

Comment on lines +66 to +70
if (!string.IsNullOrWhiteSpace(currentValue) && currentValue!.Contains(":"))
{
// Config file holds the key directly
candidateKey = currentValue;
}
Copy link
Member

Choose a reason for hiding this comment

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

This condition is not enough -do we have other indicators?


ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddProviders(ValueProviders));

// NEW: overlay values from Microsoft.Extensions.Configuration providers
Copy link
Member

Choose a reason for hiding this comment

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

Remove this info "NEW"...

// Defaults & shared configs
ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddProviders(ValueProviders));

// NEW: even here we can try to fill from providers
Copy link
Member

Choose a reason for hiding this comment

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

Remove this info "NEW"...

config = CreateConfig(confType, ConfigState.Generated, "Config file not found! Running on default values.");

// Defaults & shared configs
ValueProviderExecutor.Execute(config, new ValueProviderExecutorSettings().AddProviders(ValueProviders));
Copy link
Member

Choose a reason for hiding this comment

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

Executes the value provider (e.g- default values...) I wonder why this was not applied before?


// NEW: hook up IConfiguration from the host
var configuration = serviceProvider.GetService<IConfiguration>();
if (configuration != null)
Copy link
Member

Choose a reason for hiding this comment

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

isn't the property filled by the service collection?!

Comment on lines +153 to +160
private ConfigManager CreateManager(IConfiguration configuration)
{
return new ConfigManager
{
ConfigDirectory = _tempDir,
Configuration = configuration
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Private methods to the bottom of the class -> under the tests

Comment on lines +22 to +23
// NEW: hook into Microsoft.Extensions.Configuration
public IConfiguration? Configuration { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Remove this info "NEW"..., add a well descriptive Summary

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.

3 participants