-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utiliza Options Pattern para aplicar as configurações necessárias para a API rodar corretamente.
- Loading branch information
1 parent
2cb2c93
commit 4a594db
Showing
8 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using JwtStore.Api.Options; | ||
|
||
namespace JwtStore.Api.Extensions; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddConfigurations(this IServiceCollection services) | ||
{ | ||
services.ConfigureOptions<SecretsOptionsSetup>(); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using JwtStore.Infrastructure.Options; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace JwtStore.Api.Options; | ||
|
||
public class SecretsOptionsSetup : IConfigureOptions<SecretsOptions> | ||
{ | ||
private const string Secrets = nameof(Secrets); | ||
private readonly IConfiguration _configuration; | ||
|
||
public SecretsOptionsSetup(IConfiguration configuration) | ||
=> _configuration = configuration; | ||
|
||
public void Configure(SecretsOptions options) | ||
=> _configuration.GetSection(Secrets) | ||
.Bind(options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
JwtStore.Infrastructure/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using JwtStore.Infrastructure.Data; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace JwtStore.Infrastructure.Extensions.DependencyInjection; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
private const string DefaultConnection = nameof(DefaultConnection); | ||
|
||
public static IServiceCollection AddPersistence(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddDbContext<AppDbContext>(options | ||
=> options.UseSqlServer(configuration.GetConnectionString(DefaultConnection)) | ||
); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace JwtStore.Infrastructure.Options; | ||
|
||
public sealed class SecretsOptions | ||
{ | ||
public string ApiKey { get; init; } = string.Empty; | ||
|
||
public string JwtPrivateKey { get; init; } = string.Empty; | ||
|
||
public string PasswordSaltKey { get; init; } = string.Empty; | ||
} |