jeudi 9 juin 2016

Singleton object with parameterized constructor

I'm developing a WCF service that using MS CRM Services. I need to initialize service instance in multiple places and this take long time to init. I solved this problem with implementing singleton pattern as below.

public sealed class MSCRM
{
   private static readonly MSCRM instance = new MSCRM();
   private static readonly IOrganizationService service =GetOrgService(true);
   static MSCRM() { }
   private MSCRM() { }

   private static MSCRM Instance { get { return instance; } }
   public static IOrganizationService Service { get { return service;} }

   private static readonly object LockThread = new object();

   private static IOrganizationService GetOrgService(bool admin = false, string callerId = null)
   {

   }
}

But I need to pass parameters that in my GetOrgService method. How can I do this ?

Aucun commentaire:

Enregistrer un commentaire