Using Autofac to do DI in a static factory method I'm using Autofac to create one of my classes inside of a static factory method Create. This code is working and I haven't noticed any side effects yet. Admittedly, I've only used it in unit-tests so far but I'm wondering whether there could be any issues with it later when I take it into production code?

public static ICommandLineExecutor Create(ILogger logger)
{
    var containerBuilder = new ContainerBuilder();

    containerBuilder
        .RegisterType&lt;CommandLineTokenizer&gt;()
        .As&lt;ICommandLineTokenizer&gt;();

    containerBuilder
        .RegisterType&lt;CommandLineParser&gt;()
        .As&lt;ICommandLineParser&gt;();

    containerBuilder
        .RegisterType&lt;CommandParameterFactory&gt;()
        .WithParameter(new TypedParameter(typeof(TypeConverter), CommandParameterFactory.DefaultConverter))
        .As&lt;ICommandParameterFactory&gt;();

    containerBuilder
        .RegisterType&lt;CommandLineExecutor&gt;()
        .WithParameter(new TypedParameter(typeof(ILogger), logger))
        .As&lt;ICommandLineExecutor&gt;();

    using (var container = containerBuilder.Build())
    using (var scope = container.BeginLifetimeScope())
    {
        return scope.Resolve&lt;ICommandLineExecutor&gt;();
    }
}
What are you registering CommandLineTokenizer etc for? this whole code block is equivalent to 

return new CommandLineExecutor(logger);


If all these types are somehow used after all (inside CommandLineExecutor .ctor?), remember that everything created  Per LifeTime scope will be disposed at exit out of using and everything created  Per Dependency scope will become your responsibility to Dispose.