public bool TryGetOrBuildAutoFactoryCreator(
            Type typeOfAutoFactory,
            Func <bool> isRegisteredInContainer,
            out Func <TUnityContainer, Delegate> createAutoFactory)
        {
            createAutoFactory = null;

            // Likely, an overwhelming majority of types
            // that are being resolved, are not parameterized func-s.
            // So we check for that first to get out of the way
            // as fast as possible.
            if (!typeOfAutoFactory.IsParameterizedFunc())
            {
                return(false);
            }

            // See if we can find an existing auto-factory before wasting time on locking.
            // If we find an existing auto-factory, that means we have decided to handle
            // the inspected type previously, and so we'll handle it now too.
            if (_existingAutoFactoryCreators.TryGetValue(typeOfAutoFactory, out createAutoFactory))
            {
                return(true);
            }

            // If a type has been explicitly registered in the container,
            // the user expects that registration to be in effect,
            // so we must leave this type alone.
            if (isRegisteredInContainer())
            {
                return(false);
            }

            lock (_existingAutoFactoriesLock)
            {
                // See if another thread created the auto-factory we are looking for,
                // while we were waiting to lock.
                if (_existingAutoFactoryCreators.TryGetValue(typeOfAutoFactory, out createAutoFactory))
                {
                    return(true);
                }

                createAutoFactory = ParameterizedAutoFactoryFactoryFactory.BuildAutoFactoryCreator <
                    TUnityContainer,
                    TResolverOverride,
                    TParameterByTypeOverride>(typeOfAutoFactory);

                _existingAutoFactoryCreators.AddOrReplace(typeOfAutoFactory, createAutoFactory);

                return(true);
            }
        }
        public string Login(string userID, string password)
        {
            try
            {
                //Note:
                //the cache key for this demo is set to be the userid - without the token -. This means that each login of the same user will overwrite his/her previous session (if any)

                var loginSession = new LoginSession(userID, password);             //TODO: makde LoginSession am injectable dependency
                cache.AddOrReplace(userID, loginSession, TimeSpan.FromMinutes(1)); //TODO: make timeout configurable
                return(loginSession.AuthenticationIdentifier);
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }