I have been looking into the Castle project and specifically Windsor. I have been so impressed with what is possible with this technology and the benefits of having a such a loosely coupled system are definitely apparent. The only thing I am unsure of is if using this method has any downsides, specifically in asp.net? for example performance hits, etc.
I am trying to make the benefits of this approach visible to my fellow developers here and am being hit with the following comebacks:
That is using reflection and each time that an object is called from the container, reflection must used so performance will be terrible. (Is this the case? does it use reflection on every call?)
If I am relying on Interfaces; how do I deal with objects that have extra methods and properties which have been tacked onto the class? (through inheritance)
Significant start-up costs, almost no performance hit during operation (no reflection for calls, of course - everything's compiled during instantiation). Windsor is a bit on a heavy side, but with proper lifetime management shouldn't cause any problems.
A more important downside is that integration problems are not caught during build, and some not even at launch. Without carefull tracking of all modules' versions and continuous testing of whole system it's easy to get in trouble. Reflection helps here, so Windsor is better in that aspect than many other DI frameworks.
One problem with Castle Windsor I came across is that it is not able to run in Medium Trust (without recompilation which I was not able to do). So I needed to switch from Windsor to Unity.
According to DI/IoC performance - I believe that the performance hit is not large especially when you keep in mind the power it has.
BTW: If you are beginning with DI/IoC, you should read this MSDN article.
To answer your questions:
You also can have class components, but they have limitations, and you must be aware of those (for example you can't intercept calls to non-virtual methods). I have found Windsor to be the most mature, and best suited to my style of development container of all.
Other than that, Performance, I haven't heard of a project that had to discard dependency container because of unacceptable performance. Windsor is really smart about it, and it caches the results of lengthy operations so that you don't have to pay the price twice. You may find charts on the Internet, comparing speed of many IoC containers. Two things to note about those: All containers are really fast. Don't think that the fact that other containers are faster on these charts than Windsor, means that they are better. Windsor does a lot of stuff for you that other containers don't.
Concerning the performance, see these articles:
But remember that some of these containers have newer (and probably faster) versions - especially Unity.
As far as know all the good containers (Castle Windsor included here) do use reflection to create new instances. However this is improve performance. This is to compare with Activator.CreateInstance which is much slower. Some other Containers are quite fast though and can compete with the new operator. See comparison bench mark here. Castle Windsor is not from the high performant ones however the speed is not really important. When it comes to IoC use in application. 90% of your classes should be instated as singletones and this means work at the startup of your application only.
Try this tutorial and this tutorials. It will reveal answer to your question. If you want to avoid problems of design and easy to maintain software I would highly recommend going for SOLID practices
I've used IoC containers (Spring.NET and StructureMap) in several production apps under high load (not Facebook/MySpace high, but enough to stress out a few servers).
In my experience, even before I started using IoC, the biggest perf concern is the database and the interaction with the database -- optimizing queries, indexes, using 2nd-level caching, etc.
If you have a database involved with your app, then whatever performance hit Windsor or any other container may cause will be so infintessimally small compared to a DB round trip.
This is like people who compare the performance hit of the new() operator vs. Activator.CreateInstance() at 1-10ms when a single DB roundtrip is usually an order of magnitude more expensive.
I would advise you not to worry about the small stuff and concentrate on the big stuff.
Also, I'd like to advise you to look at StructureMap, as I believe it has a lot more functionality than Windsor and doesn't have a lot of Windsor's shortcomings (i.e. holding on to references and requiring you to release them, etc).