CDCavell.ApplicationConfiguration
2.0.0
dotnet add package CDCavell.ApplicationConfiguration --version 2.0.0
NuGet\Install-Package CDCavell.ApplicationConfiguration -Version 2.0.0
<PackageReference Include="CDCavell.ApplicationConfiguration" Version="2.0.0" />
paket add CDCavell.ApplicationConfiguration --version 2.0.0
#r "nuget: CDCavell.ApplicationConfiguration, 2.0.0"
// Install CDCavell.ApplicationConfiguration as a Cake Addin #addin nuget:?package=CDCavell.ApplicationConfiguration&version=2.0.0 // Install CDCavell.ApplicationConfiguration as a Cake Tool #tool nuget:?package=CDCavell.ApplicationConfiguration&version=2.0.0
ApplicationConfiguration
ASP.NET 9.0 Service utilized to bind ApplicationConfiguration section of configuration environment into a custom class for dependency injection
<hr />
<hr />
ApplicationConfiguration is a .Net 9.0 Service utilized to bind ApplicationConfiguration section of configuration environment into a custom class for dependency injection.
Target Framework is ASP.NET Core 9.0. Developed and built in a Windows environment utilizing Visual Studio Community 2022 source-code editor.
This work is licensed under the MIT License. Assets are licensed under their respective licensing.
<hr />
To utilize, add following to Program.cs
where AppConfig
is custom class to bind
ApplicationConfiguration section to:
private static AppConfig? _applicationConfiguration;
...
var builder = WebApplication.CreateBuilder(args);
_applicationConfiguration = new(builder.Configuration);
builder.Services.AddApplicationConfigurationService(options =>
{
options.ApplicationConfiguration = _applicationConfiguration;
});
Example of custom class (requires IConfiguration passed into constructor):
public class AppConfig(IConfiguration configuration) : ApplicationConfiguration.Models.ApplicationConfiguration(configuration)
{
}
If configuration environment has sections under ApplicationConfiguration section, then each section is it's own class within custom class. Example:
public class AppConfig(IConfiguration configuration) : ApplicationConfiguration.Models.ApplicationConfiguration(configuration)
{
public ConnectionStrings ConnectionStrings { get; set; } = new();
}
public class ConnectionStrings
{
public string ApplicationDbConnection { get; set; } = string.Empty;
}
Custom class can now be utilized in dependency injection:
public abstract class ApplicationBaseController<T>(
ILogger<T> logger,
IApplicationConfigurationService applicationConfigurationService
) : WebBaseController<ApplicationBaseController<T>>(logger) where T : ApplicationBaseController<T>
{
protected readonly AppConfig _applicationConfiguration = applicationConfigurationService.ToObject<AppConfig>();
}
<hr />
Authenticate to GitHub Packages:
<br />Replace USERNAME
with your GitHub User Name
<br />Replace YOUR_GITHUB_PAT
with your personal access token
<br />Replace NAMESPACE
with the name of the personal account or organization to which your packages are scoped
> dotnet nuget add source --username USERNAME --password YOUR_GITHUB_PAT --store-password-in-clear-text --name github "https://nuget.pkg.github.com/NAMESPACE/index.json"
Publish Package:
<br />Replace PACKAGE
with your NuGet Package Name
<br />Replace YOUR_GITHUB_PAT
with your personal access token
> dotnet nuget push "bin/Release/PACKAGE.nupkg" --api-key YOUR_GITHUB_PAT --source "github"
<hr />
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.0)
- Microsoft.Extensions.Options (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.