I have the following code snippet in my application:
The way to do this to create this instance manually up front as follows:
var service = new YourService(); services.AddScoped<IMyInterface, MyService>(); services.AddSingleton<YourService>(service);
Just as it is wise to separate the registration process from use (as the Microsoft.Extensions.DependencyInjection library correctly forces), this kind of separation is important between loading/building configuration and making the container registrations. Doing register-resolve-register is unsupported by libraries like MS DI, Autofac and Simple Injector, because it can lead to lots of complexity and subtle bugs.