thepasserby
thepasserby

Reputation: 5

C# CallContext class can store 2 keys?

Existing code:

public abstract class MyProjectDb: DB
{ 
    public static DB ActualDb
    {
        get
        {
            DB d1 = CallContext.GetData("_d1_") as DB;
            if (d1 == null)
            {
                d1 = new DB(Settings.AppServerCon1);
                CallContext.SetData("_d1_", d1);
            }
            return d1;
        }
    }
}

d1 is setting only once. Than it is getting from GetData method.

I have created similar one, for second db connection. But d2 is always getting null. Why i cant get d2 from GetData method? i mean each time d2 is filled with SetData method.

public abstract class MyProjectDbSecond : DB
{
    public static DB ActualDbSecond
    {
        get
        {
            DB d2 = CallContext.GetData("_d2_") as DB;
            if (d2 == null)
            {
                d2 = new DB(Settings.AppServerCon2);
                CallContext.SetData("_d2_", d2);
            }
            return d2;
        }
    }
}

Upvotes: 0

Views: 56

Answers (0)

Related Questions