TestServer.Configuration.InMemorySettings
2.0.0
See the version list below for details.
dotnet add package TestServer.Configuration.InMemorySettings --version 2.0.0
NuGet\Install-Package TestServer.Configuration.InMemorySettings -Version 2.0.0
<PackageReference Include="TestServer.Configuration.InMemorySettings" Version="2.0.0" />
paket add TestServer.Configuration.InMemorySettings --version 2.0.0
#r "nuget: TestServer.Configuration.InMemorySettings, 2.0.0"
// Install TestServer.Configuration.InMemorySettings as a Cake Addin #addin nuget:?package=TestServer.Configuration.InMemorySettings&version=2.0.0 // Install TestServer.Configuration.InMemorySettings as a Cake Tool #tool nuget:?package=TestServer.Configuration.InMemorySettings&version=2.0.0
TestServer.Configuration.InMemorySettings
Background
To streamline configuration in my Microsoft.NET.Sdk.Web
projects I usually create POCO like objects like this:
public class Settings
{
public string ApplicationName { get; set; }
public SwaggerSettings SwaggerSettings { get; set; } = new();
//.. snip for brevity ..
public static Settings From(IConfiguration configuration)
{
var settings = new Settings();
configuration.Bind(settings);
return settings;
}
}
public class Startup
{
private readonly Settings _settings;
public Startup(IConfiguration configuration)
{
_settings = Settings.From(configuration);
//.. snip for brevity ..
}
}
I also really love Microsoft.AspNetCore.TestHost.
While using this tool I have run into the whole configuration of settings yack shaving a couple of times.
To address this problem Microsoft have created MemoryConfigurationBuilderExtensions
in Microsoft.Extensions.Configuration which adds the following extension method:
public static IConfigurationBuilder AddInMemoryCollection(this IConfigurationBuilder configurationBuilder, IEnumerable<KeyValuePair<string, string>> initialData);
This is a pretty clean solution, would it not be that I now have to create a IEnumerable<KeyValuePair<string, string>>
and keep that in sink.
This is my solution to that problem. As I already have a Settings
object I just want to convert this to the required IEnumerable<KeyValuePair<string, string>>
Usage
var settings = new Settings
{
ApplicationName = "ApplicationName"
//.. snip for brevity ..
};
TestServer testServer = new WebHostBuilder().UseEnvironment("Test")
.UseStartup<Startup>()
.ConfigureAppConfiguration(builder =>
{
builder.AddSettings(settings)
});
Disclamer
The reflection I'm using to accomplish this conversion is quite naive and past experience has tought me that there are bugs in this code. If you find a scenario that doesn't work for you please submit a issue.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 5.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.