We are now going to talk about a mechanism to automatically load classes from other assemblies and another one for spawning background threads automatically. The first is used by .NET to automatically register certain extensions (namely for Azure and Application Insights), and the second is for performing work in the background, without getting in the way of the web app. Let's start with hosting code from external assemblies.
Hosting startup
There is an interface, IHostingStartup, that exposes a single method:
public class CustomHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
}
}
This can be used at the host start up time to inject additional behavior into the host. IWebHostBuilder is exactly the same instance that is used in the Program.Main method. So, how is this class loaded? This is done in one of two ways:
- By adding a [HostingStartup] attribute at the assembly level...