//using Autofac.Core.Registration;
//using Autofac.Features.Indexed;
//using MAX.Core.DependencyInjection;
//using MAX.Core.Infrastructure;
//using System;
//using System.Collections.Concurrent;
//using System.Collections.Generic;
//namespace Store.Client
//{
// ///
// /// 从 Autofac Keyed Service 中获取服务配置。
// /// 登录后服务端下发的新地址会保存在运行时配置中,并优先于 Keyed DI 初始配置。
// ///
// public sealed class ServiceConfigProvider : IServiceConfigProvider, ISingletonDependency
// {
// private readonly IIndex _configs;
// private readonly ConcurrentDictionary _runtimeConfigs = new ConcurrentDictionary();
// public ServiceConfigProvider(IIndex configs)
// {
// _configs = configs ?? throw new ArgumentNullException(nameof(configs));
// }
// public IApiServerConfig Get(string key)
// {
// if (TryGet(key, out IApiServerConfig config))
// {
// return config;
// }
// throw new InvalidOperationException($"未注册 Key 为“{key}”的 IApiServerConfig。");
// }
// public bool TryGet(string key, out IApiServerConfig config)
// {
// config = null;
// if (string.IsNullOrWhiteSpace(key))
// {
// return false;
// }
// if (_runtimeConfigs.TryGetValue(key, out config))
// {
// return true;
// }
// try
// {
// config = _configs[key];
// return config != null;
// }
// catch (KeyNotFoundException)
// {
// return false;
// }
// catch (ComponentNotRegisteredException)
// {
// return false;
// }
// }
// public void Set(string key, IApiServerConfig config)
// {
// if (string.IsNullOrWhiteSpace(key))
// {
// throw new ArgumentException("服务配置 Key 不能为空。", nameof(key));
// }
// if (config == null)
// {
// throw new ArgumentNullException(nameof(config));
// }
// _runtimeConfigs[key] = config;
// }
// public void Set(string key, string host, string objUrl)
// {
// Set(key, new ServiceConfig(host, objUrl));
// }
// public void SetHost(string key, string host)
// {
// string objUrl = TryGet(key, out IApiServerConfig config)
// ? config.ObjUrl
// : string.Empty;
// Set(key, new ServiceConfig(host, objUrl));
// }
// public bool Remove(string key)
// {
// return !string.IsNullOrWhiteSpace(key) && _runtimeConfigs.TryRemove(key, out _);
// }
// }
//}