Skip to content

Commit

Permalink
Merge pull request #174 from pengweiqhca/master
Browse files Browse the repository at this point in the history
统一Apollo包版本号
  • Loading branch information
pengweiqhca authored Nov 8, 2021
2 parents 7636243 + c4525d8 commit a3768ef
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 122 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Ignore Visual Studio temporary files, build results, and
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
Expand All @@ -20,6 +20,7 @@ x64/
build/
[Bb]in/
[Oo]bj/
.idea/

# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/
Expand Down
4 changes: 4 additions & 0 deletions Apollo.AspNet.Demo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public void Configuration(IAppBuilder app)
var key = context.Request.Query["key"];
if (string.IsNullOrWhiteSpace(key)) return Task.CompletedTask;
var con = ConfigurationManager.ConnectionStrings[key];
if (con != null)
return context.Response.WriteAsync($"{con.Name} {nameof(con.ConnectionString)}: {con.ConnectionString}, {nameof(con.ProviderName)}: {con.ProviderName}");
var useLegend = DateTime.Now.Second % 2 == 1;
var value = useLegend ? ConfigurationManager.AppSettings[key] : Global.Configuration[key];
if (value != null) context.Response.StatusCode = 200;
Expand Down
5 changes: 2 additions & 3 deletions Apollo.AspNetCoreHosting/Apollo.AspNetCoreHosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<PropertyGroup>
<AssemblyName>Com.Ctrip.Framework.Apollo.AspNetCoreHosting</AssemblyName>
<DefineConstants>$(DefineConstants);AspNetCoreHosting</DefineConstants>
<PackageReleaseNotes>2.4.1:
与Microsoft.AspNetCore.Hosting集成</PackageReleaseNotes>
<PackageReleaseNotes>发布日志请点击打开 https://github.com/apolloconfig/apollo.net/releases/tag/v$(ApolloVersion)</PackageReleaseNotes>
<Description>携程Apollo客户端

  与Microsoft.Extensions.Configuration集成请使用Com.Ctrip.Framework.Apollo.Configuration包
Expand All @@ -16,7 +15,7 @@ $(PackageReleaseNotes)</Description>
<PackageProjectUrl>$(RepositoryUrl)/$(MSBuildProjectName)</PackageProjectUrl>
<RootNamespace>Microsoft.AspNetCore.Hosting</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.4.1</Version>
<Version>$(ApolloVersion)</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions Apollo.ConfigAdapter.Yaml/Apollo.ConfigAdapter.Yaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

<PropertyGroup>
<AssemblyName>Com.Ctrip.Framework.Apollo.ConfigAdapter.Yaml</AssemblyName>
<Description>添加对yml和yaml格式的namespace支持,使用YamlConfigAdapter.Register()添加支持。</Description>
<PackageIconUrl>https://raw.githubusercontent.com/apolloconfig/apollo/master/apollo-portal/src/main/resources/static/img/config.png</PackageIconUrl>
<PackageProjectUrl>$(RepositoryUrl)/$(MSBuildProjectName)</PackageProjectUrl>
<PackageReleaseNotes>添加对yml和yaml格式的namespace支持,使用YamlConfigAdapter.Register()添加支持。</PackageReleaseNotes>
<PackageReleaseNotes>发布日志请点击打开 https://github.com/apolloconfig/apollo.net/releases/tag/v$(ApolloVersion)</PackageReleaseNotes>
<Description>添加对yml和yaml格式的namespace支持,使用YamlConfigAdapter.Register()添加支持。

$(PackageReleaseNotes)</Description>
<PackageTags>$(PackageTags) yml yaml</PackageTags>
<RootNamespace>Com.Ctrip.Framework.Apollo.ConfigAdapter</RootNamespace>
<TargetFrameworks>net40;net45;netstandard2.0</TargetFrameworks>
<Version>2.2.0</Version>
<Version>$(ApolloVersion)</Version>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Apollo\Apollo.csproj" />
<PackageReference Include="YamlDotNet" Version="8.*" />
<PackageReference Include="YamlDotNet" Version="11.*" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Apollo.Configuration.Demo/Apollo.Configuration.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 1 addition & 5 deletions Apollo.Configuration.Demo/ConfigurationDemo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Com.Ctrip.Framework.Apollo;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
Expand All @@ -23,9 +22,6 @@ public ConfigurationDemo()
services.AddOptions()
.Configure<Value>(context.Configuration)
.Configure<Value>("other", context.Configuration.GetSection("a"));
#pragma warning disable 618
services.AddSingleton<ApolloConfigurationManager>();
#pragma warning restore 618
})
.Build();

Expand Down
6 changes: 4 additions & 2 deletions Apollo.Configuration/Apollo.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<PropertyGroup>
<AssemblyName>Com.Ctrip.Framework.Apollo.Configuration</AssemblyName>
<PackageReleaseNotes>2.4.1:
<PackageReleaseNotes>2.4.2:
1. 完全禁用ApolloConfigurationManager
2.4.1:
1. 支持从配置中读取apollo namespace(key apollo:Namespaces,值为数组,后面优先)
2.4.0:
1. 添加apollo 1.6访问密钥
Expand Down Expand Up @@ -30,7 +32,7 @@ $(PackageReleaseNotes)</Description>
<PackageProjectUrl>$(RepositoryUrl)/$(MSBuildProjectName)</PackageProjectUrl>
<RootNamespace>Com.Ctrip.Framework.Apollo</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.4.1</Version>
<Version>$(ApolloVersion)</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 6 additions & 7 deletions Apollo.Configuration/ApolloConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static IApolloConfigurationBuilder AddApollo(this IConfigurationBuilder b
public static IApolloConfigurationBuilder AddApollo(this IConfigurationBuilder builder, IApolloOptions options)
{
var repositoryFactory = new ConfigRepositoryFactory(options ?? throw new ArgumentNullException(nameof(options)));
#pragma warning disable 618
ApolloConfigurationManager.SetApolloOptions(repositoryFactory);
#pragma warning restore 618

ApolloConfigurationManagerHelper.SetApolloOptions(repositoryFactory);

var acb = new ApolloConfigurationBuilder(builder, repositoryFactory);
if (options is ApolloOptions ao && ao.Namespaces != null)
if (options is ApolloOptions { Namespaces: { } } ao)
foreach (var ns in ao.Namespaces) acb.AddNamespace(ns);

return acb;
Expand Down Expand Up @@ -65,9 +65,8 @@ source is ApolloConfigurationProvider apollo &&
else
{
builder.Add(new ApolloConfigurationProvider(sectionKey, configRepository));
#pragma warning disable 618
ApolloConfigurationManager.Manager.Registry.Register(@namespace, new DefaultConfigFactory(builder.ConfigRepositoryFactory));
#pragma warning restore 618

ApolloConfigurationManagerHelper.Manager.Registry.Register(@namespace, new DefaultConfigFactory(builder.ConfigRepositoryFactory));
}

return builder;
Expand Down
22 changes: 13 additions & 9 deletions Apollo.Configuration/ApolloConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ namespace Com.Ctrip.Framework.Apollo
/// <summary>
/// Entry point for client config use
/// </summary>
[Obsolete("不建议使用,推荐使用Microsoft.Extensions.Configuration.IConfiguration")]
[Obsolete("不建议使用,后续版本可能删除,推荐使用Microsoft.Extensions.Configuration.IConfiguration", true)]
public class ApolloConfigurationManager
{
private static IConfigManager? _manager;

public static IConfigManager Manager => _manager ?? throw new InvalidOperationException("请在使用之前调用AddApollo");

internal static void SetApolloOptions(ConfigRepositoryFactory factory) =>
Interlocked.CompareExchange(ref _manager, new DefaultConfigManager(new DefaultConfigRegistry(), factory), null);
public static IConfigManager Manager => ApolloConfigurationManagerHelper.Manager;

/// <summary>
/// Get Application's config instance. </summary>
Expand All @@ -34,9 +29,8 @@ internal static void SetApolloOptions(ConfigRepositoryFactory factory) =>
public Task<IConfig> GetConfig(string namespaceName)
{
if (string.IsNullOrEmpty(namespaceName)) throw new ArgumentNullException(nameof(namespaceName));
if (_manager == null) throw new InvalidOperationException("请先配置Apollo");

return _manager.GetConfig(namespaceName);
return Manager.GetConfig(namespaceName);
}

/// <summary>
Expand All @@ -56,5 +50,15 @@ public async Task<IConfig> GetConfig(IEnumerable<string> namespaces)
return new MultiConfig(await Task.WhenAll(namespaces.Reverse().Distinct().Select(GetConfig)).ConfigureAwait(false));
}
}

internal class ApolloConfigurationManagerHelper
{
private static IConfigManager? _manager;

public static IConfigManager Manager => _manager ?? throw new InvalidOperationException("请在使用之前调用AddApollo");

internal static void SetApolloOptions(ConfigRepositoryFactory factory) =>
Interlocked.CompareExchange(ref _manager, new DefaultConfigManager(new DefaultConfigRegistry(), factory), null);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net471</TargetFrameworks>
<TargetFrameworks>net461;net471;netcoreapp3.1</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<Compile Remove="ConfigurationBuilderTest.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="xunit" Version="2.*" />
Expand All @@ -14,9 +18,9 @@
<ProjectReference Include="..\Apollo.ConfigurationManager\Apollo.ConfigurationManager.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<Reference Include="System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System.Configuration" />
<Reference Include="System.ServiceModel" />
</ItemGroup>

</Project>
39 changes: 4 additions & 35 deletions Apollo.ConfigurationManager/Apollo.ConfigurationManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,7 @@

<PropertyGroup>
<AssemblyName>Com.Ctrip.Framework.Apollo.ConfigurationManager</AssemblyName>
<PackageReleaseNotes>2.4.4:
1. 添加Key2XmlConfigurationBuilder和NodeReplaceSectionBuilder,方便直接替换节点内容
2. ConnectionStringsSectionBuilder支持读取特定的keyPrefix
2.4.3:
1. Apollo配置参数支持优先从环境变量读取,具体请参考项目README(如何优先使用环境变量)
2.4.2:
1. 修复AppSettingsSectionBuilder丢失value长度为0的key
2.4.1:
1. 通过重置ConfigurationManager.s_initState值强制刷新ConfigurationManager配置
2.4.0:
1. 添加apollo 1.6访问密钥
2.3.0:
1. 添加ICacheFileProvider支持自定义配置缓存方式(比如本地加密存储)
2.2.0:
1. 使用C# 8、添加nullable
2. 添加net40支持
2.1.0:
1. 无
2.0.5:
1. ApolloConfigurationManager初始化异常后,每次调用抛出有意义的异常
2.0.4:
1. AppSettingsSectionBuilder默认强制更新(forceUpdate属性配置)AppSettings,实现ConfigurationManager.AppSettings的动态更新(其他的仍然不支持动态更新)
2.0.3:
1. 无
2.0.2:
1. ApolloConfigurationManager标记为Obsolete
2.0.1:
1. 过滤重复的Namespace
2.0.0:
1. 添加json、xml等格式的namespace的支持,通过扩展名识别格式
2. 支持从环境变量读取apollo配置值
3. 添加对.net core风格key支持,优先级低于原来的key</PackageReleaseNotes>
<PackageReleaseNotes>发布日志请点击打开 https://github.com/apolloconfig/apollo.net/releases/tag/v$(ApolloVersion)</PackageReleaseNotes>
<Description>携程Apollo客户端

  与Microsoft.Extensions.Configuration集成请使用Com.Ctrip.Framework.Apollo.Configuration包
Expand All @@ -46,8 +15,8 @@ $(PackageReleaseNotes)</Description>
<PackageProjectUrl>$(RepositoryUrl)/$(MSBuildProjectName)</PackageProjectUrl>
<PackageTags>$(PackageTags) ConfigurationBuilder ConfigurationManager</PackageTags>
<RootNamespace>Com.Ctrip.Framework.Apollo</RootNamespace>
<TargetFrameworks>net471;net45;net40;netstandard2.0</TargetFrameworks>
<Version>2.4.3</Version>
<TargetFrameworks>net471;net45;net40;netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>$(ApolloVersion)</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -56,7 +25,7 @@ $(PackageReleaseNotes)</Description>
</AssemblyAttribute>

<ProjectReference Include="..\Apollo\Apollo.csproj" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.*" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
Expand Down
8 changes: 7 additions & 1 deletion Apollo.ConfigurationManager/ApolloConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class ApolloConfigurationBuilder : ConfigurationBuilder
{
private static readonly object Lock = new();
private static readonly FieldInfo ConfigurationManagerReset = typeof(ConfigurationManager).GetField("s_initState", BindingFlags.NonPublic | BindingFlags.Static)!;
public static bool AppSettingsInitialized { get; private set; }

private IConfig? _config;
public IReadOnlyList<string>? Namespaces { get; private set; }
Expand All @@ -23,7 +24,12 @@ public override void Initialize(string name, NameValueCollection config)
{
Namespaces = config["namespace"]?.Split(new[] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

if (this is not AppSettingsSectionBuilder) _ = ConfigurationManager.AppSettings; //让AppSettings必须最先被初始化
if (this is not AppSettingsSectionBuilder)
{
_ = ConfigurationManager.AppSettings; //让AppSettings必须最先被初始化

AppSettingsInitialized = true;
}

base.Initialize(name, config);
}
Expand Down
2 changes: 1 addition & 1 deletion Apollo.ConfigurationManager/ApolloConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Com.Ctrip.Framework.Apollo
#if NET471
[Obsolete("不建议使用,推荐使用System.Configuration.ConfigurationBuilder + System.Configuration.ConfigurationManager")]
#elif NETSTANDARD
[Obsolete("不建议使用,推荐安装包Com.Ctrip.Framework.Apollo.Configuration")]
[Obsolete("不建议使用,后续版本可能删除,推荐安装包Com.Ctrip.Framework.Apollo.Configuration", true)]
#endif
public static class ApolloConfigurationManager
{
Expand Down
5 changes: 2 additions & 3 deletions Apollo.ExtensionsHosting/Apollo.ExtensionsHosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<AssemblyName>Com.Ctrip.Framework.Apollo.ExtensionsHosting</AssemblyName>
<PackageReleaseNotes>2.4.1:
与Microsoft.Extensions.Hosting集成</PackageReleaseNotes>
<PackageReleaseNotes>发布日志请点击打开 https://github.com/apolloconfig/apollo.net/releases/tag/v$(ApolloVersion)</PackageReleaseNotes>
<Description>携程Apollo客户端

  与Microsoft.Extensions.Configuration集成请使用Com.Ctrip.Framework.Apollo.Configuration包
Expand All @@ -15,7 +14,7 @@ $(PackageReleaseNotes)</Description>
<PackageProjectUrl>$(RepositoryUrl)/$(MSBuildProjectName)</PackageProjectUrl>
<RootNamespace>Microsoft.Extensions.Hosting</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.4.1</Version>
<Version>$(ApolloVersion)</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions Apollo.Tests/ConfigServiceLocatorTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Com.Ctrip.Framework.Apollo;
using System;
using Com.Ctrip.Framework.Apollo;
using Com.Ctrip.Framework.Apollo.Internals;
using Com.Ctrip.Framework.Apollo.Util.Http;
using Moq;
Expand All @@ -16,7 +17,8 @@ public async Task MetaServerTest()
var moq = new Mock<IApolloOptions>();
moq.SetupGet(o => o.AppId).Returns("apollo-client");
moq.SetupGet(o => o.MetaServer).Returns("http://106.54.227.205:8080/");
moq.SetupGet(o => o.ConfigServer).Returns(new string[0]);
moq.SetupGet(o => o.ConfigServer).Returns(Array.Empty<string>());
moq.SetupGet(o => o.Timeout).Returns(5000);

var options = moq.Object;

Expand Down
13 changes: 9 additions & 4 deletions Apollo.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
# Visual Studio Version 17
VisualStudioVersion = 17.0.31825.309
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.Configuration.Demo", "Apollo.Configuration.Demo\Apollo.Configuration.Demo.csproj", "{D78C920D-C96B-4973-BBC8-35E5DB54DF2A}"
EndProject
Expand All @@ -13,7 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.ConfigurationManager
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52301167-7BBA-48C2-BA36-08270D57D2C4}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
.travis.yml = .travis.yml
azure-pipelines.yml = azure-pipelines.yml
Directory.Build.props = Directory.Build.props
PackAllProject.ps1 = PackAllProject.ps1
README.md = README.md
EndProjectSection
EndProject
Expand Down Expand Up @@ -45,9 +50,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.OpenApi.DependencyIn
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.OpenApi.Tests", "Apollo.OpenApi.Tests\Apollo.OpenApi.Tests.csproj", "{62AB1893-C173-41C7-9884-46A199244B13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollo.ExtensionsHosting", "Apollo.ExtensionsHosting\Apollo.ExtensionsHosting.csproj", "{65DED7CA-9B84-45AE-84D4-13400A3842D7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.ExtensionsHosting", "Apollo.ExtensionsHosting\Apollo.ExtensionsHosting.csproj", "{65DED7CA-9B84-45AE-84D4-13400A3842D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apollo.AspNetCoreHosting", "Apollo.AspNetCoreHosting\Apollo.AspNetCoreHosting.csproj", "{78AB89DD-1D81-4619-8750-2DABDA071FD4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Apollo.AspNetCoreHosting", "Apollo.AspNetCoreHosting\Apollo.AspNetCoreHosting.csproj", "{78AB89DD-1D81-4619-8750-2DABDA071FD4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Loading

0 comments on commit a3768ef

Please sign in to comment.