Skip to content

Commit

Permalink
extract json source to separate project
Browse files Browse the repository at this point in the history
a separate nuget to reduce dependencies in the core project
  • Loading branch information
rofr committed Oct 3, 2019
1 parent 3b4f59b commit 704937f
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ public class AppSettingsJsonSource : SettingsSource
{

/// <summary>
/// Path separator for nested properties and array indicies
/// Path separator used in the output
/// </summary>
private string _separator = ".";

private string _path;

private Dictionary<string, string> _data;

/// <summary>
/// Create an instance of AppSettingsJsonSource
/// </summary>
/// <param name="path">Path to the json file to load</param>
public AppSettingsJsonSource(string path)
{
_path = path;
Expand Down Expand Up @@ -59,7 +63,6 @@ private void Load(JsonValue node, Stack<string> path = null)

protected override IEnumerable<(string, string)> GetSettings()
{
var comparer = StringComparer.InvariantCultureIgnoreCase;
var text = File.ReadAllText(_path);
var root = (JsonObject)JsonValue.Parse(text);
_data = new Dictionary<string,string>();
Expand Down
11 changes: 11 additions & 0 deletions Fig.AppSettingsJson/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Fig
{
public static class Extensions
{
public static SettingsBuilder UseAppSettingsJson(this SettingsBuilder builder, string fileNameTemplate, bool required)
{
builder.AddFileBasedSource(file => new AppSettingsJsonSource(file), fileNameTemplate, required);
return builder;
}
}
}
24 changes: 24 additions & 0 deletions Fig.AppSettingsJson/Fig.AppSettingsJson.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.2.0</PackageVersion>
<Authors>Robert Friberg et al</Authors>
<Copyright>Robert Friberg et al</Copyright>
<Title>Fig.AppSettingsJson</Title>
<Description>Fig configuration source provider for appSettins.json files</Description>
<PackageProjectUrl>https://github.com/rofr/fig</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/rofr/fig</PackageLicenseUrl>
<RepositoryUrl>https://github.com/rofr/fig</RepositoryUrl>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Fig.Core\Fig.Core.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Json" Version="4.6.0" />
</ItemGroup>

</Project>
6 changes: 4 additions & 2 deletions Fig.AppSettingsXml/Fig.AppSettingsXml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.1.0</PackageVersion>
<PackageVersion>1.2.0</PackageVersion>
<Title>Fig.AppSettingsXml</Title>
<Authors />
<Authors>Robert Friberg et al</Authors>
<Description>Fig support for web.config or app.config in .NET Framework</Description>
<PackageProjectUrl>https://github.com/rofr/fig</PackageProjectUrl>
<RepositoryUrl>https://github.com/rofr/fig</RepositoryUrl>
<PackageReleaseNotes>initial beta release, please report any bugs</PackageReleaseNotes>
<Copyright>Robert Friberg et al</Copyright>
<PackageLicenseUrl>https://github.com/rofr/fig</PackageLicenseUrl>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Fig.Core/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Fig.Test")]
[assembly: InternalsVisibleTo("Fig.AppSettingsJson")]
10 changes: 4 additions & 6 deletions Fig.Core/Fig.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
<PackOnBuild>true</PackOnBuild>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Fig</PackageId>
<PackageVersion>1.1.0</PackageVersion>
<PackageVersion>1.2.0</PackageVersion>
<Title>Fig</Title>
<Authors />
<Authors>Robert Friberg et al</Authors>
<Description>A library to help you load and access configuration data from files, environment variables and the command line.</Description>
<PackageProjectUrl>https://github.com/rofr/fig</PackageProjectUrl>
<RepositoryUrl>https://github.com/rofr/fig</RepositoryUrl>
<Copyright>Robert Friberg et al</Copyright>
<PackageLicenseUrl>https://github.com/rofr/fig</PackageLicenseUrl>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Json" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
Expand Down
8 changes: 1 addition & 7 deletions Fig.Core/SettingsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,7 @@ private void Add(SettingsDictionary settingsDictionary)
_compositeDictionary.Add(settingsDictionary);
}

public SettingsBuilder UseAppSettingsJson(string fileNameTemplate, bool required)
{
AddFileBasedSource(file => new AppSettingsJsonSource(file), fileNameTemplate, required);
return this;
}

private void AddFileBasedSource(Func<string,SettingsSource> sourceFactory, string fileNameTemplate, bool required)
internal void AddFileBasedSource(Func<string,SettingsSource> sourceFactory, string fileNameTemplate, bool required)
{
var fileName = _compositeDictionary.ExpandVariables(fileNameTemplate);
var fullPath = Path.Combine(_basePath, fileName);
Expand Down
1 change: 1 addition & 0 deletions Fig.Tests/Fig.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fig.AppSettingsJson\Fig.AppSettingsJson.csproj" />
<ProjectReference Include="..\Fig.Core\Fig.Core.csproj" />
<ProjectReference Include="..\Fig.AppSettingsXml\Fig.AppSettingsXml.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Fig.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void MissingPropertyWithoutDefaultFailsValidation()
public void BuilderBonanza()
{
var settings = new SettingsBuilder()
.UseCommandLine(new []{"--fig:MySettings.=coffee", "--fig:"})
.UseCommandLine(new []{"--fig:MySettings.DefaultBeverage=coffee"})
.UseEnvironmentVariables(prefix: "FIG_")
.BasePath(Directory.GetCurrentDirectory())
.UseAppSettingsJson(fileNameTemplate: "appSettings.${CONFIG}.json", required: false)
Expand Down
8 changes: 7 additions & 1 deletion Fig.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fig.Core", "Fig.Core\Fig.Core.csproj", "{69520B02-715D-4140-BEB3-A4A8D0DA8E7D}"
Expand All @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fig.Tests", "Fig.Tests\Fig.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fig.AppSettingsXml", "Fig.AppSettingsXml\Fig.AppSettingsXml.csproj", "{DC6F740C-F5DE-4230-AF6E-1BA243C4F95A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fig.AppSettingsJson", "Fig.AppSettingsJson\Fig.AppSettingsJson.csproj", "{D51AF7ED-8BBA-451D-8601-B25BBB507450}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,5 +32,9 @@ Global
{DC6F740C-F5DE-4230-AF6E-1BA243C4F95A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC6F740C-F5DE-4230-AF6E-1BA243C4F95A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC6F740C-F5DE-4230-AF6E-1BA243C4F95A}.Release|Any CPU.Build.0 = Release|Any CPU
{D51AF7ED-8BBA-451D-8601-B25BBB507450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D51AF7ED-8BBA-451D-8601-B25BBB507450}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D51AF7ED-8BBA-451D-8601-B25BBB507450}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D51AF7ED-8BBA-451D-8601-B25BBB507450}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 10 additions & 2 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
nuget push Fig.Core/bin/Debug/*.nupkg -Source https://api.nuget.org/v3/index.json
nuget push Fig.AppSettingsxml/bin/Debug/*.nupkg -Source https://api.nuget.org/v3/index.json

configuration=$1
version=$2

echo $configuration
echo $version

nuget push Fig.Core/bin/$configuration/Fig.$version.nupkg -Source https://api.nuget.org/v3/index.json
nuget push Fig.AppSettingsxml/bin/$configuration/Fig.AppSettingsXml.$version.nupkg -Source https://api.nuget.org/v3/index.json
nuget push Fig.AppSettingsJson/bin/$configuration/Fig.AppSettingsJson.$version.nupkg -Source https://api.nuget.org/v3/index.json

0 comments on commit 704937f

Please sign in to comment.