public UserSessionMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                     IRouteDataService routeDataService, IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next = next;

            _routeData = new List <RouteData>();

            UserSessionSettings Settings = settingsProvider.GetSettings <UserSessionSettings>(Constants.UserSessionConfiguration);

            Settings.SessionTimeout = Shared.Utilities.CheckMinMax(Settings.SessionTimeout, 15, 200);

            UserSessionManager.InitialiseSessionManager(new TimeSpan(0, (int)Settings.SessionTimeout, 0));

            SessionHelper.InitSessionHelper();

            if (!String.IsNullOrWhiteSpace(Settings.CookieName))
            {
                _cookieName = Settings.CookieName;
            }

            if (!String.IsNullOrWhiteSpace(Settings.EncryptionKey))
            {
                _cookieEncryptionKey = Settings.EncryptionKey;
            }

            if (!String.IsNullOrWhiteSpace(Settings.StaticFileExtensions))
            {
                _staticFileExtension = Settings.StaticFileExtensions;
            }

            _defaultCulture = Settings.DefaultCulture;

            LoadLoggedInOutData(routeProvider, routeDataService, pluginTypesService);
            LoadLoggedInData(routeProvider, routeDataService, pluginTypesService);
            LoadLoggedOutData(routeProvider, routeDataService, pluginTypesService);
        }