Eaf.KeyVault.AspNetCore 9.1.0

Prefix Reserved
dotnet add package Eaf.KeyVault.AspNetCore --version 9.1.0
                    
NuGet\Install-Package Eaf.KeyVault.AspNetCore -Version 9.1.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="Eaf.KeyVault.AspNetCore" Version="9.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eaf.KeyVault.AspNetCore" Version="9.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Eaf.KeyVault.AspNetCore" />
                    
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 Eaf.KeyVault.AspNetCore --version 9.1.0
                    
#r "nuget: Eaf.KeyVault.AspNetCore, 9.1.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 Eaf.KeyVault.AspNetCore@9.1.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=Eaf.KeyVault.AspNetCore&version=9.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Eaf.KeyVault.AspNetCore&version=9.1.0
                    
Install as a Cake Tool

Eaf.KeyVault.AspNetCore

Descrição Técnica

O Eaf.KeyVault.AspNetCore é um módulo de integração ASP.NET Core para o Eaf.KeyVault. Este módulo fornece carregamento automático de configurações e segredos do Azure Key Vault ou Oracle Cloud Infrastructure (OCI) Vault diretamente no sistema de configuração do ASP.NET Core.

Este módulo simplifica a integração de segredos gerenciados em nuvem com aplicações ASP.NET Core, permitindo que configurações sensíveis sejam carregadas automaticamente durante o startup da aplicação.

Relação com o EAF e ASP.NET Boilerplate

Integração com ABP

  • Abp: Framework base para injeção de dependência e configuração

Dependências do EAF

  • Eaf.KeyVault: Módulo base de gerenciamento de segredos

Dependências Externas

  • Microsoft.Extensions.Hosting.Abstractions: Integração com hosting do ASP.NET Core
  • Microsoft.Extensions.Configuration.Abstractions: Sistema de configuração do ASP.NET Core

Principais Componentes

KeyVault Configuration Builder

Builder de configuração que carrega segredos do Key Vault:

  • Integração com IConfigurationBuilder
  • Carregamento automático durante startup
  • Suporte a recarregamento de configurações
Hosting Integration

Integração com ASP.NET Core Hosting:

  • Configuração automática no startup
  • Injeção de dependência
  • Gerenciamento de ciclo de vida

Guia de Instalação

Pré-requisitos

  • .NET 10.0 SDK ou superior
  • ASP.NET Boilerplate 10.4.0
  • Eaf.KeyVault 10.4.0
  • Azure Key Vault ou OCI Vault configurado

Instalação via NuGet

dotnet add package Eaf.KeyVault.AspNetCore --version 10.4.0

Instalação via Referência de Projeto

Adicione a referência ao seu arquivo .csproj:

<ProjectReference Include="..\Eaf.KeyVault.AspNetCore\Eaf.KeyVault.AspNetCore.csproj" />

Exemplo Básico de Uso

1. Registrando o Módulo

No Startup.cs ou Program.cs:

[DependsOn(
    typeof(EafKeyVaultAspNetCoreModule),
    typeof(EafKeyVaultModule)
)]
public class MyWebModule : AbpModule
{
    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
    }
}

2. Configurando no Startup

public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddEafKeyVaultAspNetCore(options =>
        {
            options.Provider = "Azure";
            options.Azure.VaultName = "my-vault-name";
            options.Azure.TenantId = "your-tenant-id";
            options.Azure.ClientId = "your-client-id";
            options.Azure.ClientSecret = "your-client-secret";
        });
    }
}

3. Usando Configurações do Key Vault

public class MyService : ApplicationService
{
    private readonly IConfiguration _configuration;

    public MyService(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public string GetSecret()
    {
        return _configuration["MySecret"];
    }

    public string GetConnectionString()
    {
        return _configuration["ConnectionStrings:Default"];
    }
}

4. Carregando Configuration do Key Vault

public class Startup
{
    public IConfigurationRoot Configuration { get; }

    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEafKeyVault(); // Adiciona Key Vault como fonte de configuração

        Configuration = builder.Build();
    }
}

5. Mapeando Segredos para Configurações

{
  "KeyVault": {
    "SecretMappings": {
      "MyApp--ConnectionString": "ConnectionStrings:Default",
      "MyApp--ApiKey": "ApiSettings:ApiKey",
      "MyApp--SmtpPassword": "Smtp:Password"
    }
  }
}

6. Recarregamento de Configurações

public void ConfigureServices(IServiceCollection services)
{
    services.AddEafKeyVaultAspNetCore(options =>
    {
        options.Provider = "Azure";
        options.Azure.VaultName = "my-vault-name";
        options.Azure.TenantId = "your-tenant-id";
        options.Azure.ClientId = "your-client-id";
        options.Azure.ClientSecret = "your-client-secret";
        options.ReloadOnChange = true;
        options.ReloadInterval = TimeSpan.FromMinutes(5);
    });
}

Estrutura do Módulo

Eaf.KeyVault.AspNetCore/
├── Hosting/               # Integração com ASP.NET Core Hosting
├── EafKeyVaultAspNetCoreModule.cs  # Módulo ABP
└── Eaf.KeyVault.AspNetCore.csproj  # Projeto

Configurações Opcionais

Configuração de Prefixo de Segredos

public void ConfigureServices(IServiceCollection services)
{
    services.AddEafKeyVaultAspNetCore(options =>
    {
        options.SecretPrefix = "MyApp--";
    });
}

Configuração de Exclusão de Segredos

public void ConfigureServices(IServiceCollection services)
{
    services.AddEafKeyVaultAspNetCore(options =>
    {
        options.ExcludedSecrets = new[] { "TestSecret", "DevSecret" };
    });
}

Configuração de OCI Vault

public void ConfigureServices(IServiceCollection services)
{
    services.AddEafKeyVaultAspNetCore(options =>
    {
        options.Provider = "OCI";
        options.OCI.VaultId = "ocid1.vault.oc1...";
        options.OCI.Region = "us-ashburn-1";
        options.OCI.TenancyId = "ocid1.tenancy.oc1...";
        options.OCI.UserId = "ocid1.user.oc1...";
        options.OCI.Fingerprint = "your-fingerprint";
        options.OCI.PrivateKeyFilePath = "path/to/private_key.pem";
        options.OCI.PrivateKeyPassphrase = "your-passphrase";
    });
}

Testes

Os testes para este módulo devem ser criados seguindo o padrão dos outros módulos do EAF.

Licença

Este projeto faz parte do Enterprise Application Foundation (EAF) e está licenciado sob os mesmos termos do projeto principal.

Suporte

Para issues e perguntas, consulte o repositório principal do EAF: https://github.com/afonsoft/EAF

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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

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
9.1.0 59 6/17/2026