all groups > dotnet distributed apps > november 2004 >
You're in the

dotnet distributed apps

group:

How do you call a singleton contructor before first client connect


How do you call a singleton contructor before first client connect Ralph Flaugher
11/4/2004 1:53:20 PM
dotnet distributed apps: I am creating a singleton server object. I would like to have the host
application call the server object's constructor. It appears that the
singleton object is not created until the first client attaches.

--
Re: How do you call a singleton contructor before first client connect Sam Santiago
11/4/2004 9:07:58 PM
Check out this link regarding the Dynamic Publication features of .NET
remoting:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconRemotingExampleDynamicPublication.asp

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
[quoted text, click to view]

RE: How do you call a singleton contructor before first client connect Leon Welicki
11/5/2004 1:37:01 AM
Hi Ralph,

Why would you want to call the constructor of the singleton? The constructor
in the singleton pattern specified in the GoF book is protected

Here is an excerpt of the pattern in the GoF, taken from the Implementation
section of the Singleton pattern in the book "Design Patterns"

<i>"Notice that the constructor is protected. A client that tries to
instantiate Singleton directly will get an error at compile-time. This
ensures that only one instance can ever get created."</i>

Take a look at this article, that explains several ways to implement the
Singleton pattern in C#

http://www.yoda.arachsys.com/csharp/singleton.html

if you are working with remoting, maybe you would find this article
interesting

http://www.codeproject.com/dotnet/remotingsingleton.asp


Hope this helps,
Regards,
Leon

[quoted text, click to view]
RE: How do you call a singleton contructor before first client con Ralph Flaugher
11/5/2004 6:12:02 AM
Let me explain a little better. I want to create a remote object which
contains a thread so it does work even when no client is attached. I want to
create a process which has an interface which can be accessed via .net
remoting. A singleton seems like the best solution. Right now I have my
thread started in my remote classes constructor. In my tests the thread is
not started until the first client attaches (thus, I assume, creating the
remote object) for the first time). I need a way to create the remote object
and thus start the thread whenever the host app is started not after the
first client attaches.

Ralph

[quoted text, click to view]
Re: How do you call a singleton contructor before first client con sancerre
11/5/2004 7:08:45 AM
When using either SingleCall or Singleton objects, the necessary
instances will be created dynamically during a Client's request. When
you want to publish a certain object instance that's been precreated
on the server - for example, one using a nondefault constructor -
neither alternative provides you with a solution. In this case you can
use RemotingServices.Marshal() to publish a given instance that behaves
like a Singleton afterwards. The only difference is that the object has
to already exist at the server before publication.

-- Sancerre
AddThis Social Bookmark Button