ASP.NET Core - IStartupConfigureServicesFilter not working

6 c# asp.net asp.net-core

My project has a core library with a IWebHostBuilder extension that registers several services for all my ASP.NET Core apps that utilize it:

public static IWebHostBuilder ChaseDefaults<TStartup>(this IWebHostBuilder builder) where TStartup : class
        {
            builder = builder
                    .ConfigureServices((ctx, services) => services.AddSingleton<IStartupFilter>(new MyStartupFilter(ctx, services)))
                    .UseStartup<TStartup>()
                    .UseSetting(WebHostDefaults.ApplicationKey, ApplicationEnvironment.Name);

            return builder;
        }
Run Code Online (Sandbox Code Playgroud)

I'm using the IStartupFilter interface to register a startup filter in order to call a few middlewares before the host's Startup.Configure method is called, which works great:

public class MyStartupFilter : IStartupFilter
{
    private readonly WebHostBuilderContext _context;

    public MyStartupFilter(WebHostBuilderContext context, IServiceCollection services)
    {
        _context = context;
    }

    public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
    {
        return (app) =>
        {
                // Some middlewares

                next(app);
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

However, I also want to achieve the same behavior for ConfigureServices. To achieve this, I called a custom ConfigureServices method in my constructor of my startup filter. However, it does not seem right to do it this way.

I found about the IStartupConfigureServicesFilter which is in order to register a few services before the host's Startup.ConfigureServices method is called. I know this interface is deprecated, however I do still want to use it to achieve my goal as I can't think of another solution.

When I tested things, it seems like ASP.NET Core is ignoring this filter, and when searching on ASP.NET Core source code on GitHub it seems like there are no references for it at all.

Any idea how to achieve what I want without the use of this deprecated filter?