コード例 #1
0
ファイル: ConfigService.cs プロジェクト: zt06640/apollo.net
 static ConfigService()
 {
     try
     {
         ComponentsConfigurator.DefineComponents();
         s_configManager = ComponentLocator.Lookup <ConfigManager>();
     }
     catch (Exception ex)
     {
         ApolloConfigException exception = new ApolloConfigException("Init ConfigService failed", ex);
         logger.Error(exception);
         throw exception;
     }
 }
コード例 #2
0
        static ConfigService()
        {
            try
            {
                ApolloConfigSection = ApolloConfigSettingHelper.GetApolloConfigSettings();

                ComponentsConfigurator.DefineComponents();
                s_configManager = ComponentLocator.Lookup <IConfigManager>();

                // 初始化 namespace
                var namespaceSection = (ApolloConfigNameSpacesSection)ConfigurationManager.GetSection(ApolloConfigNameSpacesSection.CONFIG_SECTION_NAME);
                if (namespaceSection != null && namespaceSection.Namespaces != null && namespaceSection.Namespaces.Count > 0)
                {
                    foreach (var namespaceEle in namespaceSection.Namespaces)
                    {
                        if (namespaceEle is NamespaceElement namespaceElement && !string.IsNullOrWhiteSpace(namespaceElement.Value) && !ConfigNamespaces.Contains(namespaceElement.Value.Trim()))
                        {
                            ConfigNamespaces.Add(namespaceElement.Value.Trim());
                        }
                    }
                }
                if (ConfigNamespaces == null || ConfigNamespaces.Count == 0)
                {
                    ConfigNamespaces.Add(ConfigConsts.NAMESPACE_APPLICATION);
                }

                foreach (var namesp in ConfigNamespaces)
                {
                    var config = GetConfig(namesp);
                    s_configManager.Configs.TryAdd(namesp, config);
                }
            }
            catch (Exception ex)
            {
                ApolloConfigException exception = new ApolloConfigException("Init ConfigService failed", ex);
                logger.Error(exception);
                throw exception;
            }
        }