0
votes

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.

1
Why don't you measure it yourself? - svick
Yeah - thanks for the help @svick. Why have StackOverflow.com when I can just answer everything myself? I'm after an expert in this area to save me having to do some poor attempt at profiling. - user11937
My point is, you can measure it yourself. Why should you waste experts' time on something you can do yourself? SO expects a reasonable amount of research on your part, and to me it seems you didn't do that. SO shouldn't be “I'm too lazy to do this, do it for me”, it should be “I don't know how to do this, can you do it?” - svick
Why post a comment basically saying that you can't add anything constructive to the question? Your response of "why don't you answer this question yourself" is hardly constructive. - user11937

1 Answers

2
votes

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.