/// <summary>
        /// Initialize the data context if necessary such as instantiating an Entity Framework DbContext or WCF Service Client etc.
        /// </summary>
        public virtual void InitializeDataContext(AppContextBase appContext)
        {
            this.AppContext = appContext;
            this.Data       = new T();

            IAppContextAware appContextAwareDataContext = this.Data as IAppContextAware;

            if (appContextAwareDataContext != null)
            {
                appContextAwareDataContext.InitializeFromAppContext(appContext);
            }
        }
        /// <summary>
        /// Initialize the app service. Throws an exception if the context has already been set.
        /// </summary>
        internal void InitializeAppService(AppContextBase appContext)
        {
            if (_appContext == null)
            {
                _appContext = appContext;

                OnInitialize();
            }
            else
            {
                throw new InvalidOperationException("App service has already been initialized.");
            }
        }
 /// <summary>
 /// Initializes the class for use by an inherited class instance. This constructor can only be called by an inherited class.
 /// </summary>
 protected AppServicesBase(AppContextBase appContext)
 {
     InitializeAppService(appContext);
 }