ModularStart - Abstract the BuildServiceProvider line

I’d like to switch out my default DI container. You’d normally do that by implementing public IServiceProvider ConfigureServices(IServiceCollection services) but the ModularStart base class doesn’t have that method marked as virtual – and for good reason, it does a lot!

I was wondering if we could get the actual building of the service provider to be abstracted away as a virtual method so we can overwrite that final bit. So instead of that function calling return services.BuildServiceProvider(); it would call some virtual function e.g. BuildServiceProvider(services) which I could then override to do my thing.

I’m following this tutorial: https://dzone.com/articles/adding-a-custom-dependency-injection-container-in

What my end goal is, is to generate a wrapped IServiceProvider that calls the base implementation, but also then uses reflection (and caching!) to do property injection on the type. I have some legacy types that would be a pain to refactor to use the constructor so I’d like to give this method a go first.

If you would like to submit a PR with whatever features you like in the old ModularStartup I’d be happy to look at merging.

However I would recommend that you move to using ASP.NET Core’s native [HostingStartup] Model instead which we’ve moved all our .net6.0 project templates to use:

https://docs.servicestack.net/releases/v5_13#new-modular-startup

Where dependencies are registered using ASP.NET Core’s ConfigureServices() and alternative IOC’s are supported in a .NET Generic Host using UseServiceProviderFactory, e.g: