While it's usually advised to keep your code unaware of Windsor, it's sometimes desirable that components themselves specify knowledge about how they should be used by Windsor.
Attributes are mostly useful for extensions
Most common usage of attributes is extensions/customizations to Windsor itself. For "normal" components prefer either explicit of convention driven wiring.
In addition to Lifestyle attributes that components can use to specify their preferred lifestyle, Windsor also has a more broadly applicable attribute -
. Using this attribute you can specify not only lifestyle but also name and service of the component.
[CastleComponent("GenericRepository", typeof (IRepository<>), Lifestyle = LifestyleType.Transient)]
public class Repository<T> : IRepository, IRepository<T>
// some implementation
CastleComponentAttribute specifies defaults
If you register a component using the attribute and then change some of the values in your registration code, the explicitly set value will win. In other words - the attribute specifies defaults, how the component prefers to be registered, but you can override that.
Registering attributed components
You register attributed components much like you would register any other type.
is a helper filter method, that will return true for classes that have