All 3 methods called from AddServices are calling Register(..) one by one, leading to an exponential number of List/Set operations as a function of the number of implementations added. This is because every call can potentially trigger IKernelInternal.OptimizeDependencyResolution(), which in turn will iterate through all handlers in order to check and update the state if the handler now has every depedency satisfied. With this wrapper, the installer will be called by the container itself, deferring this check until all registrations are done.
On two big monolithic projects I have worked on that have lots of CQRS type handlers; a web API and a background eventhandler/processor, doing what amounts to the same change reduced the time spent by ApplicationHostBuilder.Build() more than 10x, previously approaching almost 2 minutes on developer machines, worse on CI/CD VMs.
All 3 methods called from AddServices are calling Register(..) one by one, leading to an exponential number of List/Set operations as a function of the number of implementations added. This is because every call can potentially trigger IKernelInternal.OptimizeDependencyResolution(), which in turn will iterate through all handlers in order to check and update the state if the handler now has every depedency satisfied. With this wrapper, the installer will be called by the container itself, deferring this check until all registrations are done.
On two big monolithic projects I have worked on that have lots of CQRS type handlers; a web API and a background eventhandler/processor, doing what amounts to the same change reduced the time spent by ApplicationHostBuilder.Build() more than 10x, previously approaching almost 2 minutes on developer machines, worse on CI/CD VMs.