HLCores.Utilities.SettingsConfig 2.0.0

dotnet add package HLCores.Utilities.SettingsConfig --version 2.0.0                
NuGet\Install-Package HLCores.Utilities.SettingsConfig -Version 2.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HLCores.Utilities.SettingsConfig" Version="2.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HLCores.Utilities.SettingsConfig --version 2.0.0                
#r "nuget: HLCores.Utilities.SettingsConfig, 2.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HLCores.Utilities.SettingsConfig as a Cake Addin
#addin nuget:?package=HLCores.Utilities.SettingsConfig&version=2.0.0

// Install HLCores.Utilities.SettingsConfig as a Cake Tool
#tool nuget:?package=HLCores.Utilities.SettingsConfig&version=2.0.0                

HLCores.Utilities.SettingsConfig

HLCores.Utilities.SettingsConfig is a utility get a valued stored in the appsettings.

Features

  • static string GetCurrentSettings(stringkey).
  • static T GetCurrentSettings(stringkey).

Usage

Exam:

public async Task<OperationResult> Create(BaseDto dto)
{
     using SqlConnection conn = new(SettingsConfigUtility.GetCurrentSettings("ConnectionStrings:DefaultConnection"));
     await conn.OpenAsync();

     string cmdText = $"SELECT * FROM {dto.Entity} WHERE IsDelete = 0 AND Code = '{dto.Code}'";

     SqlCommand cmd = GetCommand(cmdText, conn);

     var execute = await cmd.ExecuteScalarAsync();

     if (execute is not null)
     {
          await cmd.DisposeAsync();
          return new OperationResult { IsSuccess = false, Message = $"{dto.Message} đã tồn tại. Vui lòng thử lại !!!" };
     }

     try
     {
          cmdText = $"INSERT INTO {dto.Entity} (Code, Title, Status, IsDelete, CreateBy, CreateTime) VALUES ('{dto.Code}', '{dto.Title}', {(dto.Status.Value ? 1 : 0)}, {(dto.IsDelete.Value ? 1 : 0)}, '{dto.CreateBy}', '{dto.CreateTime}')";
          cmd = GetCommand(cmdText, conn);

          await cmd.ExecuteNonQueryAsync();
          return new OperationResult { IsSuccess = true };
      }
      catch (Exception ex)
      {
           return new OperationResult { IsSuccess = false, Message = ex.Message };
      }
      finally
      {
           await cmd.DisposeAsync();
      }
}
private static readonly MailSettingServer mailSetting = SettingsConfigUtility<MailSettingServer>.GetCurrentSettings("MailSettingServer");

public static void SendMail(string content, string subject, List<string> mailTos, bool isBodyHtml = false)
{
     MailMessage mail = MailConfiguration(content, subject, mailTos, isBodyHtml);

     // The important part -- configuring the SMTP client
     SmtpClient smtp = GetSmtpClient(mailSetting);

     smtp.Send(mail);
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 89 12/15/2024
1.0.0 130 8/16/2024