They're not really singletons....the problem is related though.


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Shawn
Wildermuth (MVP)
Sent: 27 April 2007 12:32
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Serialising almost singletons....

I don't get the issue.  Why are you serializing the singleton?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthconsulting.com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
Sent: Friday, April 27, 2007 7:03 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Serialising almost singletons....

I've got a solution...it isn't especially pleasant though.

I pretty much implement the singleton code as published.......but use

ISerializable.GetObjectData

To explicitly push the state for the "SingletonSerializationHelper" to
recreate the 'singleton'

It's unpleasant because I have 1 class having to know the internal
structure of another class.....it's a bug waiting to happen.

Is there a better way?


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark
Sent: 27 April 2007 11:41
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Serialising almost singletons....

I have a problem very similar (but not quite the same) as serialization
of
singletons...e.g.

with a singleton, you serialise it, deserialise it, and now effectively
have a clone of the original.....well documented and I know how to get
around it (even if I don't understand exactly the dot net serialisation
mechanism).

My problem is similar, I have a set of objects that are created via a
factory and are unique for their specific state.....so for example if
the
class was

class Person
{
   public Person(string name);
}

class PersonFactory
{
   IDictionary<string,Person> uniquePeople = ...bla bla

   Person GetPerson(string name)
   {
      if (!uniquePeople.ContainsKey(name))
      {
         uniquePeople.Add(name, new Person(name));
      }

      return uniquePeople[name];
   }
}


The examples of how to handle singletons don't explain how to handle
state......i.e. as it's a singleton, the state is the state of the
singleton currently in memory.

Can you help?

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to