volosoft / castle-windsor-ms-adapter

Castle Windsor ASP.NET Core / Microsoft.Extensions.DependencyInjection Adapter
https://www.nuget.org/packages/Castle.Windsor.MsDependencyInjection
MIT License
85 stars 29 forks source link

Wrap AddServices in an IWindsorInstaller to reduce registration/startup time #46

Closed baodden closed 6 months ago

baodden commented 7 months ago

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.

ismcagdas commented 7 months ago

Thanks a lot @baodden I will check your PR soon.