user11937
user11937

Reputation:

Castle Windsor IoC "cost"

Where is the performance cost of using Castle Windsor for dependency resolution? Is it on new WindsorContainer(), or on container.Resolve<T>()?

Based on the answer to this, should an ASP.NET service initialize the Container in Application_Start, and then Resolve<T>() as required? Or Resolve<T>() also in Application_Start?

BTW - I'm aware that this could constitute premature optimization in some people's minds... I'm just looking for the correct implementation for a scalable ASP.NET service.

Upvotes: 0

Views: 914

Answers (1)

Krzysztof Kozmic
Krzysztof Kozmic

Reputation: 27374

most costly operation in most application is registering the components in the container (container.Install(FromAssembly.This())), which is something you do once per application.

Resolving, unless you're doing something really wrong, tends to have negligible cost.

To expand on registration. It's costly relatively to other things containers do. In absolute numbers it's still fast enough not to be a headache in vast majority of applications.

It takes the because that's where the containers (using Windsor as an example, since that's what you seem to be using, and I happen to know best) go to scan the assemblies (with reflection) to find the types you want to register, then inspect those types (using reflection) to build proper component model, and then feed all of that information to facilities and other extensions for inspection and possible modification. Also analysis of the dependency graph and various optimisations happen at this time, so that Windsor can do other, more frequent operations, faster after the registration process is done.

Upvotes: 2

Related Questions