Goldev.Core 8.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Goldev.Core --version 8.2.0
                    
NuGet\Install-Package Goldev.Core -Version 8.2.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="Goldev.Core" Version="8.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Goldev.Core" Version="8.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Goldev.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Goldev.Core --version 8.2.0
                    
#r "nuget: Goldev.Core, 8.2.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.
#:package Goldev.Core@8.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Goldev.Core&version=8.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Goldev.Core&version=8.2.0
                    
Install as a Cake Tool

Goldev.Core

Пакет c общими элементами внутренних библиотек Goldev

Расширения для конфигурации

В пакете реализованы расширения для конфигурации приложения

конфигурация берётся по следующим приоритетам:

  1. Переменные окружения
  2. appsettings.json
  3. значение по умолчанию
Использование:
  1. Создать Класс конфигурации

    [AutoConfiguration]
    public class TestConfiguration
    {
        [FromEnvironment("TEST_CONFIG")]
        public string Test { get; init; } = string.Empty; // по умолчанию string.Empty
    }
    
    • Атрибут AutoConfiguration говорит, что мы не будем регистрировать IOptions вручную
    • Атрибут FromEnvironment помечает свойство как свойство из переменных окружения, без него свойство будет браться только из appsetings.json
  2. Зарегистрировать класс IOptions

    • Если мы использовали атрибут AutoConfiguration
      builder.Services.AddConfigurations(builder.Configuration); // Регистрируют все классы помеченные как AutoConfiguration
      
    • Если мы не использовали атрибут AutoConfiguration
      builder.Services.ConfigureWithENV<TestConfiguration>(builder.Configuration) // Регистрирует класс TestConfiguration
      
  3. Добавить класс конфигурации в конструктор класса

    public TestHandler(IOptions<TestConfiguration> options)
    {
      _config = options.Value
    }
    
  4. Добавить значения в appsettings.json или в переменные окружения

    • appsettings.json
      {
        "TestConfiguration": "test"
      }
      
    • EnvironmentVariables
      TEST_CONFIG = "test"
      

Константы

с версии 8.0.7 добавлена возможность прокидывать статические переменные из appsettings.json

Использование:
  1. В классе прописать анотации [TrackedType] для класса и [Constant] для статического поля
    [TrackedType]
    public class TestClass
    {
       [Constant(BlockName = "Test", ConstantName = "Test1")]
       static int _test1;
    
       [Constant(BlockName = "Test", ConstantName = "Test2")]
       static TestEnum _testEnum;
    
       [Constant(BlockName = "Test")]
       static string _test3 { get; set; } = null!;
    
       [Constant(BlockName = "Test", ConstantName = "Test3")]
       static string _test5 = null!;
    
       [Constant(BlockName = "Test")]
       public static string Test4 = null!;
    
       [Constant(BlockName = "Test", ConstantName = "Test4")]
       public static string Test6 { get; set; } = null!;
    }
    
  2. В appsettings.json прописать значения
    {
      "Test": {
        "Test1": 123,
        "Test2": 3,
        "Test3": "abacaba",
        "Test4": "hello world"
      }
    }
    
  3. В program вызвать метод AddConstants();
    builder.Configuration.AddConstants();
    
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Goldev.Core:

Package Downloads
Goldev.Core.Kafka

Package Description

Goldev.Core.MediatR

Package Description

Goldev.Cache.Redis

Package Description

Goldev.Core.Logging

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.