castle-windsor Lifestyles Standard Lifestyles

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

When a Component is resolved from the Windsor container it must have a definition of the scope it is in. By scope meaning if and how it is reused and when to release the object for the Garbage Collector to destroy. This is the LifeStlye of the Component.

The way to specify a LifeStyle is by registering a component. The two most common LifeStyles are:

  1. Transient - Each time the component is resolved a new instance of it is produced by the container.

    Container.Register(Component.For<Bar>().LifestyleTransient());
    
  2. Singleton - Each time the component is resolved the same instance will be returned by the container

    Container.Register(Component.For<Foo>().LifestyleSingleton());
    

Singleton is the default lifestyle, which will be use if you don't specify any explicitly.

Other built-in LifeStyles include PerWebRequest,Scoped, Bound, PerThread, Pooled

For more details about the different lifestyles and for what each is good for, refer to Castle's Documentation



Got any castle-windsor Question?