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

[Advertisement]

Comments

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

Colin,

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

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)