Boba.Configurations is a lightweight library designed for .NET projects to simplify the process of retrieving configurations from appsettings.json files.
Boba.Configurations is conveniently available on NuGet. Simply install the provider package corresponding to your target database.
dotnet add package Boba.Configurations
Utilize the --version
option to specify a preview version for installation if needed.
Harnessing the power of Boba.Configurations is straightforward. Follow these steps to get started:
Begin by registering Boba.Configurations in your program.cs
. Presently, we support SqlServer, necessitating the provision of a connection string. Alternative data store providers are also available.
builder.Services.AddBobaConfigurations(builder.Configuration);
Define your settings class, inheriting from IConfig
. Here, you can optionally assign default values to be retrieved in the absence of stored data.
public class EmailConfig : IConfig
{
public string DefaultFromEmail { get; set; }
public int Port { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public SMTPSetting SMTPSetting { get; set; }
}
public class SMTPSetting
{
public string Host { get; set; }
}
Store your entity mapped as the EmailConfig
in appsettings.json
.
"EmailConfig": {
"DefaultFromEmail": "my.email@gmail.com",
"Port": 587,
"SMTPSetting": { "Host": "smtp.gmail.com" },
"UserName": "my.email@gmail.com",
"Password": "xxxx cccc dddd yyyy"
}
Inject the config service into your application and access the values effortlessly.
private readonly EmailConfig _emailConfig;
public YourConstructor(EmailConfig emailConfig)
{
_emailConfig = emailConfig;
}
Console.WriteLine(_emailConfig.DefaultFromEmail);
- Intuitive User Interface for simplified management.
- Query caching mechanisms for enhanced performance.
- Flexible injection options, including Windsor, Unity, Autofac, etc.
Contributions are always welcome!
See contributing.md
for ways to get started.
Please adhere to this project's code of conduct
.
The main branch is now on .NET 8.0. Previous versions are not available at this time.
This project is licensed under the MIT license.
If you encounter any issues or have questions, please feel free to raise a new issue.