private GetVersionServiceResult getVersionService(KVCacheConfiguration configuration, string versionMappingKey)
        {
            if (!configuration.VersionNameMappings.TryGetValue(versionMappingKey, out string versionName))
            {
                versionName = configuration.DefaultVersionName;
            }

            if (!_kvCacheVersionServiceFactories.TryGetValue(versionName, out IFactory <IKVCacheVersionService> serviceFactory))
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundIKVCacheVersionServiceByName,
                    DefaultFormatting = "找不到版本名称为{0}的KV缓存版本服务,发生位置为{1}",
                    ReplaceParameters = new List <object>()
                    {
                        versionName, $"{this.GetType().FullName}.KVCacheVersionServiceFactories"
                    }
                };

                throw new UtilityException((int)Errors.NotFoundIKVCacheVersionServiceByName, fragment);
            }

            return(new GetVersionServiceResult()
            {
                Service = serviceFactory.Create(), VersionName = versionName
            });
        }
Esempio n. 2
0
        private (IKVCacheVersionService, string) getVersionService(KVCacheConfiguration configuration, string versionMappingKey)
        {
            if (!configuration.VersionNameMappings.TryGetValue(versionMappingKey, out string versionName))
            {
                versionName = configuration.DefaultVersionName;
            }

            if (!_kvCacheVersionServiceFactories.TryGetValue(versionName, out IFactory <IKVCacheVersionService> serviceFactory))
            {
                //简化错误处理
                throw new Exception($"找不到版本名称为{versionName}的KV缓存版本服务");
            }

            return(serviceFactory.Create(), versionName);
        }