Making Transient as Default Lifestyle in Castle Windsor

This is actually an answer to fellow blogger Jak Charlton, but I see a benefit in sharing it.

Casey pointed out that the default lifestyle should be transient. Even though I understand his reasonings, I am used to this way.

There is a solution for those who wants Transient as the default.

You know what? Yes, the events ! Here is how.

container.Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated);

void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
	if (model.LifestyleType == LifestyleType.Undefined)
		model.LifestyleType = LifestyleType.Transient;

Posted 08-06-2009 1:30 PM by Tuna Toksoz



Colin Jack wrote re: Making Transient as Default Lifestyle in Castle Windsor
on 09-13-2009 3:16 PM

Gave this a shot and the event didn't fire, not sure why. Will give it another shot to see if I'm missing something.

Oh and having had some awful lifestyle issues recently it'd be cool if Windsor reported suspicious dependencies, such a Singleton or PerThread referencing a Transient (or giving us a really easy way to spot these issues). Maybe such support already exists and I just haven't found it though.

Tuna Toksoz wrote re: Making Transient as Default Lifestyle in Castle Windsor
on 09-13-2009 3:23 PM

Hi Colin,

I don't think such logging exists, but  i am not sure. Can you raise the issue in castle users group?

Also, If you can isolate the issue, i will be glad to take a look.

Gilligan wrote re: Making Transient as Default Lifestyle in Castle Windsor
on 09-17-2009 12:25 PM


you can log these suspicions in the DependencyResolving event. That is the best I have found so far.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)