-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: EnsureDatabase Minimal API e connection strings
- Loading branch information
1 parent
ca879b4
commit d9583bf
Showing
17 changed files
with
40 additions
and
68 deletions.
There are no files selected for viewing
Binary file modified
BIN
+88 Bytes
(100%)
src/building-blocks/DevStore.WebAPI.Core/Identity/JwtConfig.cs
Binary file not shown.
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
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
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
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
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
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
26 changes: 7 additions & 19 deletions
26
src/services/DevStore.ShoppingCart.API/Configuration/DbMigrationHelpers.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 |
---|---|---|
@@ -1,37 +1,25 @@ | ||
using DevStore.WebAPI.Core.Configuration; | ||
using DevStore.ShoppingCart.API.Data; | ||
using DevStore.WebAPI.Core.Configuration; | ||
|
||
namespace DevStore.ShoppingCart.API.Configuration | ||
{ | ||
|
||
public static class DbMigrationHelpers | ||
{ | ||
/// <summary> | ||
/// Generate migrations before running this method, you can use command bellow: | ||
/// Nuget package manager: Add-Migration DbInit -context PagamentosContext | ||
/// Dotnet CLI: dotnet ef migrations add DbInit -c PagamentosContext | ||
/// Nuget package manager: Add-Migration DbInit -context ShoppingCartContext | ||
/// Dotnet CLI: dotnet ef migrations add DbInit -c ShoppingCartContext | ||
/// </summary> | ||
public static async Task EnsureSeedData(IServiceScope serviceScope) | ||
{ | ||
var services = serviceScope.ServiceProvider; | ||
await EnsureSeedData(services); | ||
} | ||
|
||
public static async Task EnsureSeedData(IServiceProvider serviceProvider) | ||
public static async Task EnsureSeedData(WebApplication app) | ||
{ | ||
using var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope(); | ||
var env = scope.ServiceProvider.GetRequiredService<IWebHostEnvironment>(); | ||
|
||
//var configuration = scope.ServiceProvider.GetRequiredService<IConfiguration>(); | ||
var context = scope.ServiceProvider.GetRequiredService<Data.ShoppingCartContext>(); | ||
using var context = app.Services.CreateScope().ServiceProvider.GetRequiredService<ShoppingCartContext>(); | ||
|
||
await DbHealthChecker.TestConnection(context); | ||
|
||
if (env.IsDevelopment()) | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
await context.Database.EnsureCreatedAsync(); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
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
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