Skip to content

Commit a6af33f

Browse files
committed
COH-30704 Migrate from app.config to appsettings.json (and maybe other configuration providers)
[git-p4: depot-paths = "//dev/main.net/": change = 111249]
1 parent 9e8b797 commit a6af33f

File tree

6 files changed

+71
-146
lines changed

6 files changed

+71
-146
lines changed

src/Coherence/Coherence.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171

7272
<ItemGroup>
7373
<PackageReference Include="Common.Logging" Version="3.4.1" />
74-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
74+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
75+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
7576
</ItemGroup>
7677

7778
<ItemGroup>

src/Coherence/Config/CoherenceConfigHandler.cs

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/Coherence/Util/ConfigurationUtils.cs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
using System;
8-
using System.Configuration;
9-
8+
using System.Collections;
9+
using System.IO;
10+
using Microsoft.Extensions.Configuration;
1011
using Tangosol.Config;
12+
using Tangosol.IO.Resources;
1113

1214
namespace Tangosol.Util
1315
{
@@ -21,26 +23,54 @@ public class ConfigurationUtils
2123
/// The name of the configuration element that contains Coherence
2224
/// configuration settings.
2325
/// </summary>
24-
private const string CONFIG_SECTION_NAME = "coherence";
25-
26-
// TODO: remove this constant in a future release
27-
private const string _CONFIG_SECTION_NAME = "tangosol-coherence";
26+
private const string CONFIG_SECTION_NAME = "Coherence";
2827

2928
/// <summary>
3029
/// Parses the Coherence configuration section within the standard
31-
/// .NET configuration file (App.config or Web.config).
30+
/// .NET configuration file (appsettings.json).
3231
/// </summary>
3332
/// <returns>
34-
/// An instance of <see cref="CoherenceConfig"/> created by
35-
/// <see cref="CoherenceConfigHandler"/>.
33+
/// An instance of <see cref="CoherenceConfig"/>
3634
/// </returns>
3735
public static object GetCoherenceConfiguration()
3836
{
39-
// TODO: we still check for the legacy "tangosol-coherence" config
40-
// section for backwards compatibility; this check should be
41-
// removed in a future release
42-
return ConfigurationManager.GetSection(CONFIG_SECTION_NAME)
43-
?? ConfigurationManager.GetSection(_CONFIG_SECTION_NAME);
37+
IConfiguration cohCfg = new ConfigurationBuilder()
38+
.SetBasePath(Directory.GetCurrentDirectory())
39+
.AddJsonFile("appsettings.json", true)
40+
.Build()
41+
.GetSection(CONFIG_SECTION_NAME);
42+
43+
CoherenceConfig config = new CoherenceConfig();
44+
string coherenceConfig = cohCfg["CoherenceConfig"];
45+
string cacheConfig = cohCfg["CacheConfig"];
46+
string pofConfig = cohCfg["PofConfig"];
47+
string messagingDebug = cohCfg["COHERENCE_MESSAGING_DEBUG"];
48+
49+
config.ConfigProperties = new Hashtable();
50+
if (coherenceConfig != null)
51+
{
52+
config.OperationalConfig = ResourceLoader.GetResource(coherenceConfig);
53+
}
54+
if (cacheConfig != null)
55+
{
56+
config.CacheConfig = ResourceLoader.GetResource(cacheConfig);
57+
}
58+
if (pofConfig != null)
59+
{
60+
config.PofConfig = ResourceLoader.GetResource(pofConfig);
61+
}
62+
if (messagingDebug != null)
63+
{
64+
config.ConfigProperties.Add("COHERENCE_MESSAGING_DEBUG", messagingDebug);
65+
}
66+
67+
IConfigurationSection properties = cohCfg.GetSection("Properties");
68+
foreach (var property in properties.GetChildren())
69+
{
70+
config.ConfigProperties.Add(property.Key, property.Value);
71+
}
72+
73+
return config;
4474
}
4575

4676
/// <summary>

tests/Coherence.Tests/App.config

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/Coherence.Tests/Coherence.Tests.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
See https://github.com/dotnet/runtime/issues/22720 for details.
3737
-->
3838
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
39-
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\testhost.dll.config" />
40-
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\testhost.x86.dll.config" />
41-
<Copy SourceFiles="App.config" DestinationFiles="$(OutDir)\ReSharperTestRunner64.dll.config" />
39+
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\testhost.dll.config" />
40+
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\testhost.x86.dll.config" />
41+
<Copy SourceFiles="appsettings.json" DestinationFiles="$(OutDir)\ReSharperTestRunner64.dll.config" />
4242
</Target>
4343

4444
<Target Name="InstallCerts" AfterTargets="AfterBuild">
@@ -58,6 +58,9 @@
5858

5959
<ItemGroup>
6060
<None Remove="Resources\*.xml" />
61+
<None Update="appsettings.json">
62+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
63+
</None>
6164
</ItemGroup>
6265
<ItemGroup>
6366
<EmbeddedResource Include="Resources\*.xml" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"Coherence": {
9+
"CacheConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-cache-config.xml",
10+
"PofConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-config.xml",
11+
"CoherenceConfig": "assembly://Coherence.Tests/Tangosol.Resources/s4hc-test-coherence.xml",
12+
"Properties": {
13+
"coherence.proxy.port1": "9099",
14+
"coherence.serializer": "pof"
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)