From 7e60a2b5140becb5fce6c1c688816c0fd3748419 Mon Sep 17 00:00:00 2001 From: Kirill Poletaev Date: Sun, 2 Jul 2023 19:21:42 +0300 Subject: [PATCH] KeyCloak, dbcontext --- .dev/docker-compose.yml | 28 +++++++++++++++++-- Keroosha.Pechka.Web/Database/AppDbContext.cs | 21 ++++++++++++++ .../Keroosha.Pechka.Web.csproj | 2 ++ Keroosha.Pechka.Web/Program.cs | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Keroosha.Pechka.Web/Database/AppDbContext.cs diff --git a/.dev/docker-compose.yml b/.dev/docker-compose.yml index c96b426..3a28700 100644 --- a/.dev/docker-compose.yml +++ b/.dev/docker-compose.yml @@ -1,7 +1,22 @@ version: "3.8" name: "keroosha-pechka-template" -services: +services: + keycloak: + image: quay.io/keycloak/keycloak:21.1.2 + ports: + - "8080:8080" + command: +# - "start-dev --import-realm" + - "start-dev" +# volumes: +# - ./realm-export.json:/opt/keycloak/data/import/main-realm.json:ro + environment: + - "KEYCLOAK_ADMIN=admin" + - "KEYCLOAK_ADMIN_PASSWORD=admin" + networks: + resources: + db: image: postgres:15-alpine environment: @@ -9,6 +24,9 @@ services: POSTGRES_INITDB: 'pechka' ports: - "5432:5432" + networks: + resources: + minio: image: quay.io/minio/minio command: server /data --console-address ":19001" @@ -18,4 +36,10 @@ services: MINIO_ROOT_PASSWORD: 'pechka' ports: - "19000:9000" # S3 interface - - "19001:19001" # Minio console \ No newline at end of file + - "19001:19001" # Minio console + networks: + resources: + + +networks: + resources: \ No newline at end of file diff --git a/Keroosha.Pechka.Web/Database/AppDbContext.cs b/Keroosha.Pechka.Web/Database/AppDbContext.cs new file mode 100644 index 0000000..9bfc38e --- /dev/null +++ b/Keroosha.Pechka.Web/Database/AppDbContext.cs @@ -0,0 +1,21 @@ +using LinqToDB.Data; +using LinqToDB.DataProvider; +using Pechka.AspNet.Database; + +namespace Keroosha.Pechka.Web.Database; + +public class AppDbContext : DataConnection +{ + public AppDbContext(string connectionString, IDataProvider provider) : base(provider, connectionString) + { + } +} + +public class AppDbContextManager : DbContextManagerBase +{ + public AppDbContextManager(IDataProvider provider, string connectionString): + base(() => new AppDbContext(connectionString, provider)) + { + + } +} \ No newline at end of file diff --git a/Keroosha.Pechka.Web/Keroosha.Pechka.Web.csproj b/Keroosha.Pechka.Web/Keroosha.Pechka.Web.csproj index f5e64be..8e1f0e6 100644 --- a/Keroosha.Pechka.Web/Keroosha.Pechka.Web.csproj +++ b/Keroosha.Pechka.Web/Keroosha.Pechka.Web.csproj @@ -12,6 +12,8 @@ + + diff --git a/Keroosha.Pechka.Web/Program.cs b/Keroosha.Pechka.Web/Program.cs index cc1bb7e..ff5b126 100644 --- a/Keroosha.Pechka.Web/Program.cs +++ b/Keroosha.Pechka.Web/Program.cs @@ -1,5 +1,6 @@ // See https://aka.ms/new-console-template for more information +using Keroosha.Pechka.Web.Database; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -19,6 +20,7 @@ void ConfigureOptions(IConfiguration configuration, IServiceCollection services) void ConfigureManagers(IServiceCollection services) { + services.AddDbContextManager((z, x) => new AppDbContextManager(z, x)); services.AddHttpClient(); }