Subclass needs to implement Interface property as static
<p>I don't know if I"m even approaching this right so bare with me.  I'm newer to using Interfaces.  </p>

<p>My intent is that any API wrapper projects we write in the future around 3rd party or even internal APIs that need a session will need to (should by expected team pattern) implement this interface because it will enforce commonality in terms of those API Wrapper projects because I know that any session classes will always have GetCurrentSession, RenewSession, etc. in them...so we have a consistent pattern in terms of common members to be implemented for concrete session classes.</p>

<p>So here's my interface:</p>

<pre><code>/// &lt;summary&gt;
/// Represents an API end user based session
/// &lt;/summary&gt;
public interface IAPISession
{
    #region Properties

    int SessionID { get; }

    /// &lt;summary&gt;
    /// Gets the user ID.
    /// Note: type string since userID is not always int in 3rd party APIs 
    /// &lt;/summary&gt;
    /// &lt;value&gt;The user ID.&lt;/value&gt;
    string UserID { get; }

    bool SessionHasExpired { get; }

    DateTime ExpirationDate { get; }

    void LogOut(); // expires the session &amp; sets SessionHasExpired

    #endregion Properties

    #region Methods

    /// &lt;summary&gt;
    /// Renews the session by returning a brand new session 
    /// if the existing session has expired.
    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    IAPISession RenewSession();


    /// &lt;summary&gt;
    /// Gets the current API session
    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    IAPISession GetCurrentSession();

    #endregion Methods
}
</code></pre>

<p>Here is an implementation example:</p>

<pre><code>public class FacebookSession : IAPISession
{
    private static FacebookSession _singletonInstance;

    private FacebookSession() { }

    #region Properties

    private HttpContext CurrentContext { get; set; }

    private HttpCookie CurrentSessionCookie { get; set; }

    #endregion


    #region IAPISession Members

    // Checks for a current session cookie
    public bool SessionHasExpired 
    { 
        get
        {
            return _singletonInstance == null;
        }
    }

    public IAPISession RenewSession()
    {
        throw new NotImplementedException();
    }


    /// &lt;summary&gt;
    /// Gets the current API session singleton instance
    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static IAPISession GetCurrentSession()
    {
        if (SessionHasExpired)
        {
            return null;
        }

        // TODO: return the singleton instance here...

    }

    public void LogOut()
    {
        throw new NotImplementedException();
    }


    public int SessionID { get; private set; }

    public string UserID { get; private set; }

    public DateTime ExpirationDate { get; private set; }

    #endregion


    public void LogIn(HttpContext currentContext)
    {
        if (SessionHasExpired)
        {
            const string redirectUri = "http://localhost/Photo/FacebookOauth.aspx"; // page they will be redirected to after they auth
            string authUrl = ConfigUtil.GetAppConfigSetting("PayPalBaseUri") + "?client_id=" +
                             ConfigUtil.GetAppConfigSetting("PayPalClientID") +
                             "&amp;redirect_uri=" + redirectUri;

            CurrentContext.Response.Redirect(authUrl); // redirect them to log in
        }
    }
}
</code></pre>

<p>and here's my problem.  A session is a singleton for the current user thread.  To access a singleton, that method <code>GetCurrentSession()</code> which I know all APIs we create will need to implement (will be totally different in HOW they will be implemented based on the API) I need the property to be a static property to get the singleton.</p>

<p>But you can't.  Because you can't have static members in an Interface.  So...yea I could take out the Interface pattern requirement but I really don't want to.</p>

<p>FYI this is not functional code above, I'm doing my initial coding of all this and trying to design it best.</p>

<p><strong>UPDATE:</strong></p>

<p>On the topic of factories, let me step back to give you more context in what I'm doing here.  I needed to get the right custom APIService object (I create a service class for every API wrapper to work with) based on what API wrapper I'm coding for, so I created a GetService factory (or at least attempted to..have not done a lot of factories) like below.  And in it you can see that all the methods are static, properties, etc.  </p>

<p>Usage example for below would be:</p>

<pre><code>FacebookService service = PhotoServiceFactory.CurrentPhotoUploadServiceFactory;
</code></pre>

<p>Thoughts?  I'm just trying to do the same for Session but feel I would like to actually expose the related session inside the Specific Service instance that I get back from the factory.  So for instance I'd be able to do something like this:</p>

<pre><code>service.CurrentSession which would give me the current facebook singleton session.
</code></pre>

<p>The service here is FacebookService type because the factory went out to get it based on the API type I'm working with (API type is an Enum I created that has values like Facebook, Flickr, etc.)</p>

<pre><code>    public class PhotoServiceFactory
    {
        private static PhotoServiceFactory _singletonInstance;

        private PhotoServiceFactory(){}

        #region Properties

        public static PhotoUploadServiceFactory CurrentPhotoUploadServiceFactory
        {
            get
            {
                _singletonInstance = _singletonInstance ?? (_singletonInstance = new PhotoUploadServiceFactory());
                return _singletonInstance;
            } 
        }

        #endregion

        #region Methods

        public static IAPIService GetAPIService(APIType apiType)
        {
            IAPIService apiService = null;

            switch (apiType)
            {
                // return the right service singleton instance
                // based on the API type that we're working with
                case APIType.Facebook:
                    apiService = FacebookAPIService.CurrentFacebookAPIService;
                    break;
                case APIType.Flickr:
                    apiService = null; // service not implemented
                    break;
                case APIType.PhotoBucket:
                    apiService = null; // service not implemented
                    break;
                case APIType.Picasa:
                    apiService = null; // service not implemented
                    break;
                case APIType.Kodak:
                    apiService = null; // service not implemented
                    break;
            }

            return apiService;
        }

        #endregion
    }
</code></pre>
