Asp.net Emulating WebForms state in enten env env

I'm looking for an elegant way to set up my AppContext correctly, and here it is:

public class AppContext : IAppContext
{
    public AppContext()
    {
        Application = new AppStorage();    // app scoped hashtable
        Local = new LocalStorage();        // current thread scoped hashtable
        Session = new SessionStorage();    // session for some reasons hashtable
    }

    public CultureInfo Culture { get; set; }     // session scoped
    public UserProfile AuthProfile { get; set; } // session scoped

    public IStorage Application { get; private set; } // application 
    public IStorage Session { get; private set; }     // session
    public IStorage Local { get; private set; }       // current thread
    public IStorage WcfSession { get; private set; }  // wcf session

    private ISecurityWriter SecurityWriter;           // session scoped
    private ISecurityContext SecurityContext;         // session scoped

    /// 1. START WEB CONTEXT
    /// 2. START WCF CONTEXT
}

      

I am currently balancing between a)

public class Global : HttpApplication
{
    public static AppContext Context;

    protected void Application_Start(object sender, EventArgs e)
    {
       Context = new AppContext();
    }
}

      

but i don't like what ideea has

Global.Context.Sesstion.Set<Order>(theOrderInstance);

      

b) and adding the following lines to the AppContext

public class AppContext{
private static AppContext instance;

public AppContext Instance
{ 
   get{ 
        if(instance == null) 
          instance = new AppContext();
        return instance;
   }
}

      

it's not nice to look either

AppContext.Instance.Session.Set<Order>(theOrderInstance);

      

QUESTION : I like the idea of ​​having

AppContext.Session.Set<Order>(theOrderInstance);

      

any difficulty how to achieve this? something OSS and relevant to this thread would be greatly appreciated

enjoy:)

0


a source to share


2 answers


How about this path?



protected AppContext Instance
{ 
   get{ 
        if(instance == null) 
          instance = new AppContext();
        return instance;
   }
}

public IStorage Session
{ 
   get{ 
        return Instance.Session;
   }
}

      

0


a source


look here:

public static class AppContextExtensions
{
    public static AppContext Context(this Page page)
    {
        return AppContext.Instance;
    }
}

      

Using



this.Context().Session.Set<Order>(theOrderInstance)

      

and I'm happy with that :)

0


a source







All Articles