Skip to content

Commit

Permalink
Changed context
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobritodev committed Jan 3, 2020
1 parent 263fde0 commit d090866
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Client configuration
IdentityTokenLifetime = 3600,
LogoUri = "https://jpproject.azurewebsites.net/sso/images/brand/logo.png",
AuthorizationCodeLifetime = 3600,
PostLogoutRedirectUris = {$"{configuration["ApplicationSettings:IS4AdminUi"]}",},
PostLogoutRedirectUris = {"http://localhost:4300",},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AutoMapper.Configuration;
using JPProject.Admin.Application.AutoMapper;
using JPProject.Admin.Database;
using JPProject.Admin.Infra.Data.Context;
using JPProject.AspNet.Core;
using JPProject.Domain.Core.ViewModels;
using MediatR;
Expand All @@ -19,6 +20,7 @@ public static IServiceCollection ConfigureAdminUi(this IServiceCollection servic
var database = configuration.GetValue<DatabaseType>("ApplicationSettings:DatabaseType");
var connString = configuration.GetConnectionString("SSOConnection");

services.Configure<JpDatabaseOptions>(o => o.MustThrowExceptionIfDatabaseDontExist = false);
services.ConfigureJpAdmin<AspNetUser>().AddDatabase(database, connString);

return services;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using JPProject.Admin.Infra.Data.Context;
using JPProject.EntityFrameworkCore.Context;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;

namespace JPProject.Admin.Api.Configuration
{
public static class AdminUiMigrationHelpers
{
/// <summary>
/// Generate migrations before running this method, you can use command bellow:
/// Nuget package manager: Add-Migration DbInit -context ApplicationIdentityContext -output Data/Migrations
/// Dotnet CLI: dotnet ef migrations add DbInit -c ApplicationIdentityContext -o Data/Migrations
/// </summary>
public static async Task EnsureSeedData(IServiceScope serviceScope)
{
var services = serviceScope.ServiceProvider;
await EnsureSeedData(services);
}
public static async Task EnsureSeedData(IServiceProvider serviceProvider)
{
await Infra.Data.Configuration.DbMigrationHelpers.CheckDatabases(serviceProvider, new JpDatabaseOptions() { MustThrowExceptionIfDatabaseDontExist = true });

using (var scope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
var eventStoreDb = scope.ServiceProvider.GetRequiredService<EventStoreContext>();
await Infra.Data.Configuration.DbMigrationHelpers.ConfigureEventStoreContext(eventStoreDb);
}
}
}
}
8 changes: 4 additions & 4 deletions src/Backend/JPProject.Admin.Api/JPProject.Admin.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Hellang.Middleware.ProblemDetails" Version="3.1.0" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="JPProject.Admin.Application" Version="3.1.3" />
<PackageReference Include="JPProject.Admin.Database" Version="3.1.3" />
<PackageReference Include="JPProject.AspNet.Core" Version="3.1.3" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="JPProject.Admin.Application" Version="3.1.5" />
<PackageReference Include="JPProject.Admin.Database" Version="3.1.5" />
<PackageReference Include="JPProject.AspNet.Core" Version="3.1.5" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
Expand Down
11 changes: 8 additions & 3 deletions src/Backend/JPProject.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using JPProject.Admin.Api.Configuration;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using System;

namespace JPProject.Admin.Api
{
public class Program
{
public static void Main(string[] args)
{
Console.Title = "JP Project - User Management";
Console.Title = "JP Project - Admin Light API";

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
Expand All @@ -25,7 +26,11 @@ public static void Main(string[] args)
.WriteTo.Console()
.CreateLogger();

CreateHostBuilder(args).Build().Run();
var host = CreateHostBuilder(args).Build();

AdminUiMigrationHelpers.EnsureSeedData(host.Services).Wait();

host.Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Expand Down
4 changes: 2 additions & 2 deletions src/Backend/JPProject.Admin.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Postgre Connection
//"SSOConnection": "Server=localhost;Port=5432;Database=jpproject;User Id=postgres;Password=@Password1;"
// Sql Server connection
"SSOConnection": "Server=.;Initial Catalog=JpProject;Persist Security Info=False;User ID=sa;Password=@Password1;MultipleActiveResultSets=False;Connection Timeout=30;"
"SSOConnection": "Data Source=(LocalDb)\\MSSQLLocalDB;database=IdentityServer4.Quickstart.EntityFramework-3.0.0;trusted_connection=yes;"
// MySql connection
// "SSOConnection": "server=localhost,port=3306;database=jpproject;user=bruno;password=10203040"
// SQLite Connection
Expand Down Expand Up @@ -32,7 +32,7 @@
"SendEmail": "false"
},
"ApplicationSettings": {
"DatabaseType": "SqlServer",
"DatabaseType": "SQLServer",
"Authority": "https://localhost:5000",
"ApiName": "jp_api",
"ApiSecret": "Q&tGrEQMypEk.XxPU:%bWDZMdpZeJiyMwpLv4F7d**w9x:7KuJ#fy,E8KPHpKz++"
Expand Down

0 comments on commit d090866

Please sign in to comment.