Skip to content

Inject Dependencies into Command Settings #1147

Answered by wbaldoumas
wbaldoumas asked this question in Q&A
Discussion options

You must be logged in to vote

This was resolved with a pretty simple fix. I had forgotten that the actual settings class also needs to be registered:

public static class TypeRegistrarConfigurator
{
    public static ITypeRegistrar ConfigureTypeRegistrar()
    {
        var serviceCollection = new ServiceCollection();

        serviceCollection.AddSingleton<IFileSystem, FileSystem>();
        serviceCollection.AddSingleton<IFile, FileWrapper>();
        serviceCollection.AddTransient<ConvertSettings>(); // adding this fixed things

        return new TypeRegistrar(serviceCollection);
    }
}

Leaving this up in case it helps anyone else. 😄

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wbaldoumas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant