Using third-party containers
Though the built-in container is sufficient for most of our scenarios, .NET 5 provides a way to integrate with third-party containers that can be leveraged if need be.
Let's have a closer look at how the framework wires up the services. When the Startup
class is registered with HostBuilder
in Program.cs
, .NET framework uses reflection to identify and call the Configure
and ConfigureServices
methods.
Here is a snippet from the StartupLoader
class in ASP.NET Core 5:
var configureMethod = FindConfigureDelegate(startupType, environmentName); var servicesMethod = FindConfigureServicesDelegate(startupType, environmentName); var configureContainerMethod = FindConfigureContainerDelegate(startupType, environmentName);
From the preceding code, we can see that the first two methods, FindConfigureDelegate
and FindConfigureServicesDelegate
, are to find the Configure
and ConfigureServices
methods.
The last line is for ConfigureContainer
. We can define...