Singleton Service?

Topics: CAB & Smart Client Software Factory
Jul 12, 2006 at 2:36 AM
originally posted by: shahramjam

Hi!
I wonder how you can implement singleton pattern(static readonly instance ...) with private constructor in cab?
Because I think it is necesery if you want to be sure only one instance of your service can get run.

Regards
Jul 12, 2006 at 5:20 AM
originally posted by: ChrisHolmes

I think this has more to do with how you construct your class and less to do with the CAB, but I could be wrong :-)

Check here: http://www.yoda.arachsys.com/csharp/singleton.html
Jul 12, 2006 at 5:51 AM
originally posted by: PProvost

I'm trying to understand what you really want here. The singleton implementation pattern that uses private constructors and static instance methods is a particular implementation that you use when you are NOT in the presence of a service container.

When you have something like CAB and a dependency injection container, every service is a singleton--by definition.

Just add an instance of your service to the root container and you are good to go. No need to change your class' implementation.
Jul 12, 2006 at 8:59 PM
originally posted by: shahramjam

"When you have something like CAB and a dependency injection container, every service is a singleton--by definition."
Thank you for clarification.
Regards
Oct 3, 2006 at 11:22 AM
originally posted by: kovlab49

This could matter if you're taking an outside library that insists on static construction, like Log4Net, and making it available as a service within your CAB application. How could the IoC stuff in ObjectBuilder construct that in it's Services collection?
Oct 3, 2006 at 11:40 PM
originally posted by: MatthiasFG

>>When you have something like CAB and a dependency injection container, every service is a singleton--by definition.

souldn't it be more precisly:
every service is a singleton within it's container--by definition.

Because one can have more than one instances of a service class in different work items/containers?

-Matthias
Oct 3, 2006 at 11:45 PM
originally posted by: MatthiasFG

you can'tuse ObjectBuilder for constructing as long as you don't write a wrapper service.
BUT you can get you service injected into other objects by registering it as a service with calling RootWorkItem.Services.Add(serviceType under which to register, serviceInstance)?

-Matthias