Added Service Fabric configuration source
This commit is contained in:
Родитель
3c40381428
Коммит
461809079a
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26228.4
|
VisualStudioVersion = 15.0.26228.10
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -61,6 +60,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Config
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.DockerSecrets.Test", "test\Microsoft.Extensions.Configuration.DockerSecrets.Test\Microsoft.Extensions.Configuration.DockerSecrets.Test.csproj", "{82A403ED-F827-4FED-BE38-7F87925A07E1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.DockerSecrets.Test", "test\Microsoft.Extensions.Configuration.DockerSecrets.Test\Microsoft.Extensions.Configuration.DockerSecrets.Test.csproj", "{82A403ED-F827-4FED-BE38-7F87925A07E1}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.ServiceFabric", "src\Microsoft.Extensions.Configuration.ServiceFabric\Microsoft.Extensions.Configuration.ServiceFabric.csproj", "{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -171,6 +172,10 @@ Global
|
||||||
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
{82A403ED-F827-4FED-BE38-7F87925A07E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -202,5 +207,6 @@ Global
|
||||||
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
{AC7FAD2A-5763-404D-B0FC-3CCA81A16B0A} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
||||||
{69AB0230-D82E-438B-AFE5-85BFF414F1B8} = {F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}
|
{69AB0230-D82E-438B-AFE5-85BFF414F1B8} = {F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}
|
||||||
{82A403ED-F827-4FED-BE38-7F87925A07E1} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
{82A403ED-F827-4FED-BE38-7F87925A07E1} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
||||||
|
{BD8CAF12-4D1F-42F6-90B7-7CA5390CB523} = {F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<MoqVersion>4.7.1</MoqVersion>
|
<MoqVersion>4.7.1</MoqVersion>
|
||||||
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
|
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
|
||||||
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
|
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
|
||||||
|
<ServiceFabricVersion>5.5.216</ServiceFabricVersion>
|
||||||
<TestSdkVersion>15.0.0</TestSdkVersion>
|
<TestSdkVersion>15.0.0</TestSdkVersion>
|
||||||
<XunitVersion>2.2.0</XunitVersion>
|
<XunitVersion>2.2.0</XunitVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<Import Project="..\..\build\common.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<Description>Service Fabric configuration provider implementation for Microsoft.Extensions.Configuration.</Description>
|
||||||
|
<TargetFramework>net45</TargetFramework>
|
||||||
|
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<PackageTags>configuration;servicefabric</PackageTags>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.ServiceFabric" Version="$(ServiceFabricVersion)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Microsoft.Extensions.Configuration\Microsoft.Extensions.Configuration.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,47 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Fabric;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Configuration.ServiceFabric
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="ConfigurationProvider"/> for Service Fabric.
|
||||||
|
/// </summary>
|
||||||
|
public class ServiceFabricConfigurationProvider : ConfigurationProvider
|
||||||
|
{
|
||||||
|
private readonly ServiceContext _serviceContext;
|
||||||
|
private readonly string _configurationPackageName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance with Service Fabric context.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serviceContext">The Service Fabric service context.</param>
|
||||||
|
/// <param name="configurationPackageName">The name of the configuration package; defaults to "Config"
|
||||||
|
/// if not provided.</param>
|
||||||
|
public ServiceFabricConfigurationProvider(ServiceContext serviceContext,
|
||||||
|
string configurationPackageName = null)
|
||||||
|
{
|
||||||
|
_serviceContext = serviceContext ?? throw new ArgumentNullException(nameof(serviceContext));
|
||||||
|
_configurationPackageName = configurationPackageName ?? "Config";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the Service Fabric settings.
|
||||||
|
/// </summary>
|
||||||
|
public override void Load()
|
||||||
|
{
|
||||||
|
var configurationPackage = _serviceContext.CodePackageActivationContext.GetConfigurationPackageObject(
|
||||||
|
_configurationPackageName);
|
||||||
|
|
||||||
|
foreach (var section in configurationPackage.Settings.Sections)
|
||||||
|
{
|
||||||
|
foreach (var parameter in section.Parameters)
|
||||||
|
{
|
||||||
|
Data[$"{section.Name}{ConfigurationPath.KeyDelimiter}{parameter.Name}"] = parameter.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Fabric;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Configuration.ServiceFabric
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents Service Fabric settings as an <see cref="IConfigurationSource"/>.
|
||||||
|
/// </summary>
|
||||||
|
public class ServiceFabricConfigurationSource : IConfigurationSource
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The Service Fabric service context.
|
||||||
|
/// </summary>
|
||||||
|
public ServiceContext ServiceContext { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the <see cref="ServiceFabricConfigurationProvider"/> for this source.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
|
||||||
|
/// <returns>A <see cref="ServiceFabricConfigurationProvider"/></returns>
|
||||||
|
public IConfigurationProvider Build(IConfigurationBuilder builder)
|
||||||
|
{
|
||||||
|
return new ServiceFabricConfigurationProvider(ServiceContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Fabric;
|
||||||
|
|
||||||
|
namespace Microsoft.Extensions.Configuration.ServiceFabric
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for registering <see cref="ServiceFabricConfigurationProvider"/> with
|
||||||
|
/// <see cref="IConfigurationBuilder"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ServiceFabricExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds an <see cref="IConfigurationProvider"/> that reads configuration values from Service Fabric settings.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="configurationBuilder">The <see cref="IConfigurationBuilder"/> to add to.</param>
|
||||||
|
/// <param name="serviceContext">The Service Fabric service context</param>
|
||||||
|
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
|
||||||
|
public static IConfigurationBuilder AddServiceFabric(this IConfigurationBuilder configurationBuilder,
|
||||||
|
ServiceContext serviceContext)
|
||||||
|
{
|
||||||
|
configurationBuilder.Add(new ServiceFabricConfigurationSource { ServiceContext = serviceContext });
|
||||||
|
return configurationBuilder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче