Note that there are some explanatory texts on larger screens.

plurals
  1. POsingleton implementation problem in C#
    primarykey
    data
    text
    <p>--ConsoleApplication 1</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { public class MsgService { private static CreateConnectionToA _instanceA; private static CreateConnectionToB _instanceB; protected MsgService() { } public static MsgService GetInstanceA(string paramA, string paramB) { if (_instanceA != null) { return _instanceA; } return _instanceA = new CreateConnectionToA("p1","p2"); } public static MsgService GetInstanceB(string paramA, string paramB) { if (_instanceB != null) { return _instanceB; } return _instanceB = new CreateConnectionToB("p1", "p2"); } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class CreateConnectionToB : MsgService { public CreateConnectionToB(string param1, string Param2) { } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class CreateConnectionToA : MsgService { public CreateConnectionToA(string param1, string Param2) { } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { MsgService.GetInstanceA("p1", "p2"); Console.Read(); } } } </code></pre> <p>--ConsoleApplication 2</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("Press"); Console.Read(); ConsoleApplication2.MsgService.GetInstanceA("p1", "p2"); Console.Read(); } } } </code></pre> <p>I am trying to Make simgleton implementation but something is wrong with my approach. It always creates new instance of _instanceA and _instanceB from each console application.</p> <p>Can someone please point me out what needs to be done here?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload