public class AppConfiguration : IConfiguration
{
string IConfiguration.this[string key] { get => configuration[key]; set => configuration[key] = value; }
}
and this registration
CSharp
.Bind<Microsoft.Extensions.Configuration.IConfiguration>().As(Singleton).To(ctx =>
{
AppConfiguration configuration = new AppConfiguration();
....
return configuration;
})
.Bind().As(Singleton).To<TelemetryRuntime>(ctx =>
{
ctx.Inject(out Microsoft.Extensions.Configuration.IConfiguration configuration);
var a = configuration["TelemetryHost"],
....
})
Source generator generate a code
var localConfigurationM05D20di9 = _rootM05D20di._singletonAppConfigurationM05D20di35;
var a = localConfigurationM05D20di9["TelemetryHost"];
The reference type of localConfigurationM05D20di9 is AppConfiguration and not IConfiguration. Because of explicit interface implementation, the indexer is not found on AppConfiguration type instance and this fails to compile.
May be the correct generated code should look like this?
var localConfigurationM05D20di9 = (IConfiguration)_rootM05D20di._singletonAppConfigurationM05D20di35;
var a = localConfigurationM05D20di9["TelemetryHost"];
I have this class
and this registration
CSharp
Source generator generate a code
The reference type of localConfigurationM05D20di9 is AppConfiguration and not IConfiguration. Because of explicit interface implementation, the indexer is not found on AppConfiguration type instance and this fails to compile.
May be the correct generated code should look like this?