dependency-injectionautofacautofac-configurationautofac-module

Implementing IConfiguration with Autofac


im trying to use Autofac and configure an appconfig.json:

        private static void RegisterAppSettingsConfiguration(ContainerBuilder builder)
        {
            var config = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json");
            var module = new ConfigurationModule(config.Build());
            builder.RegisterModule(module);
        }

Is this all the code to set up the IConfiguration Interface? (after that, a builder.Build() of course). It doesn't find the object that implements IConfiguration:

Cannot resolve parameter 'Microsoft.Extensions.Configuration.IConfiguration config' of constructor 'Void .ctor(CamTool.Avalonia.GUI.Models.Interfaces.IGUILogger, Microsoft.Extensions.Configuration.IConfiguration)'.

When i change the name of the appsettings.json there is another exception (file not found), so that part works fine i guess. Do i need to wire up an implementation of an IConfiguration object? I thought it's been doing that behind the scenes. My other DI stuff works just fine with Autofac.

Thanks


Solution

  •      var configuration = new ConfigurationBuilder()
                    .AddJsonFile("appsettings.json")
                    .Build();
                builder.RegisterInstance<IConfiguration>(configuration);
    

    This is the solution - i had to directly use the instance of the IConfiguration and link it up by myself