How do I instantiate the core object in a web service?

The problem I have is that I would like the web service to run and have access to an object which will not get re-instatiated each time the web service is called.

I'm thinking of a Singleton, of sorts.

Can anyone tell me how to do this with a web service?  I could set an initial value to null and call a constructor in that case.  But in the case of the second call to the web service, I'd like to see that value is not null and that I can use that object.

Am I making sense?

thanks,
nbw
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
JimBrandleyCommented:
You could handle it with a property as:

private SingletonObject mSingleton = null;

public Singleton
{
   get
   {
      if (mSingleton == null)
     {
         mSingleton = new SingletonObject;
     }
      return mSingleton;
   }
}

Jim
0
 
newbiewebSr. Software EngineerAuthor Commented:
what namespace declares a SingletonObject ?
0
 
newbiewebSr. Software EngineerAuthor Commented:
I mean what

using

statement should I use so it will compile?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
JimBrandleyCommented:
Sorry - That was just the name I used for your "core" object. It is whatever you need it to be. Unless I misunderstood the question.

Jim
0
 
newbiewebSr. Software EngineerAuthor Commented:
Oh, I see.

thanks.
0
 
JimBrandleyCommented:
My pleasure. Good luck.

Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.