views:

192

answers:

1

I have a singleton class which needs to be intialized by castle? I'm a little newbie in castle. I have looked for singleton in castle and I saw setting the lifestyle attribute of component to "Singleton" seems enough. But in that case it seems I don't need to implement the class in "Singleton Pattern". Just plain class definition for my class seems ok.

Is castle provide my class as singleton to me even I define it as a normal class? Or I am missing something?

+4  A: 

No, you are absolutely right - the container will instantiate your class the first time it is needed, and from then on the instance will live inside your container.

Stay away from the singleton pattern - it is evil! :)

(no, seriously - there are very few cases where implementing a singleton is acually necessary... and if you are using an IoC container, you will never have to implement singletons by using static instances, which can seriously hurt your design by coupling your classes to those static instances)

mookid8000
Thanks for your reply. I agree in the case of singleton's evilness! :)
yapiskan
Amen. Completely agreed.
Krzysztof Koźmic