From 24ae21c9eda77ee3fe385b222224b5019ea6e9a5 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 07:05:39 +0200 Subject: [PATCH 01/18] - added database providers, db context generator, service collection generator from draft branch --- .../Nox.DatabaseProvider.SqlServer.csproj | 17 +++ .../SqlServerDatabaseProvider.cs | 49 ++++++ .../INoxDatabaseProvider.cs | 13 ++ .../Nox.DatabaseProvider.csproj | 19 +++ .../NoxDatabaseProviderException.cs | 19 +++ src/Nox.Generator.sln | 16 ++ .../ServiceCollectionExtensionGenerator.cs | 47 ++++++ .../DbContextGenerator/DbContextGenerator.cs | 141 +++++++++++------- src/Nox.Generator/Nox.Generator.cs | 8 +- src/Nox.Lib/Nox.Lib.csproj | 1 + .../Examples/CountriesController.cs | 4 +- .../Examples/SampleWebAppDbContextExample.cs | 56 ------- .../Persistence/DatabaseServerTests.cs | 53 +++++++ .../Nox.Generator.Tests.csproj | 6 + .../database-server.solution.nox.yaml | 59 ++++++++ .../yaml/infrastructure/generator.nox.yaml | 22 +++ 16 files changed, 415 insertions(+), 115 deletions(-) create mode 100644 src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj create mode 100644 src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs create mode 100644 src/Nox.DatabaseProvider/INoxDatabaseProvider.cs create mode 100644 src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj create mode 100644 src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs create mode 100644 src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs delete mode 100644 src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs create mode 100644 tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs create mode 100644 tests/Nox.Generator.Tests/files/yaml/infrastructure/database-server.solution.nox.yaml create mode 100644 tests/Nox.Generator.Tests/files/yaml/infrastructure/generator.nox.yaml diff --git a/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj b/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj new file mode 100644 index 0000000000..cdcadcbcfa --- /dev/null +++ b/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs new file mode 100644 index 0000000000..27cdcc3fb5 --- /dev/null +++ b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs @@ -0,0 +1,49 @@ +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Nox.Solution; + +namespace Nox.DatabaseProvider.SqlServer; + +public class SqlServerDatabaseProvider: INoxDatabaseProvider +{ + private string _connectionString = string.Empty; + + public string ConnectionString + { + get => _connectionString; + set => SetConnectionString(value); + } + + public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer) + { + var csb = new SqlConnectionStringBuilder(dbServer.Options) + { + DataSource = $"{dbServer.ServerUri},{dbServer.Port}", + UserID = dbServer.User, + Password = dbServer.Password, + InitialCatalog = dbServer.Name, + ApplicationName = applicationName + }; + SetConnectionString(csb.ConnectionString); + + return optionsBuilder.UseSqlServer(_connectionString, opts => + { + opts.MigrationsHistoryTable("MigrationsHistory", "migrations"); + }); + } + + public string ToTableNameForSql(string table, string schema) + { + throw new NotImplementedException(); + } + + public string ToTableNameForSqlRaw(string table, string schema) + { + throw new NotImplementedException(); + } + + private void SetConnectionString(string connectionString) + { + _connectionString = connectionString; + } +} \ No newline at end of file diff --git a/src/Nox.DatabaseProvider/INoxDatabaseProvider.cs b/src/Nox.DatabaseProvider/INoxDatabaseProvider.cs new file mode 100644 index 0000000000..109e302eb8 --- /dev/null +++ b/src/Nox.DatabaseProvider/INoxDatabaseProvider.cs @@ -0,0 +1,13 @@ +using Microsoft.EntityFrameworkCore; +using Nox.Solution; + +namespace Nox.DatabaseProvider +{ + public interface INoxDatabaseProvider + { + string ConnectionString { get; set; } + DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer); + string ToTableNameForSql(string table, string schema); + string ToTableNameForSqlRaw(string table, string schema); + } +} \ No newline at end of file diff --git a/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj b/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj new file mode 100644 index 0000000000..5d240523b5 --- /dev/null +++ b/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj @@ -0,0 +1,19 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + + diff --git a/src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs b/src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs new file mode 100644 index 0000000000..2f0ee81f08 --- /dev/null +++ b/src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs @@ -0,0 +1,19 @@ +namespace Nox.DatabaseProvider; + +[Serializable] +public class NoxDatabaseProviderException : Exception +{ + public NoxDatabaseProviderException() + { + } + + public NoxDatabaseProviderException(string message) + : base(message) + { + } + + public NoxDatabaseProviderException(string message, Exception inner) + : base(message, inner) + { + } +} \ No newline at end of file diff --git a/src/Nox.Generator.sln b/src/Nox.Generator.sln index bcd61befe6..fa85411502 100644 --- a/src/Nox.Generator.sln +++ b/src/Nox.Generator.sln @@ -57,6 +57,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.Types.EntityFramework", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.Types.Tests", "..\tests\Nox.Types.Tests\Nox.Types.Tests.csproj", "{A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DatabaseProviders", "DatabaseProviders", "{137019F4-2B62-4DD8-B2F8-0F5067205101}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider", "Nox.DatabaseProvider\Nox.DatabaseProvider.csproj", "{1D6D928A-AA0F-40F6-8930-47B695919104}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.SqlServer", "Nox.DatabaseProvider.SqlServer\Nox.DatabaseProvider.SqlServer.csproj", "{7435EFBA-471C-4BFB-A306-EB9CDF375585}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -139,6 +145,14 @@ Global {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Release|Any CPU.Build.0 = Release|Any CPU + {1D6D928A-AA0F-40F6-8930-47B695919104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D6D928A-AA0F-40F6-8930-47B695919104}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D6D928A-AA0F-40F6-8930-47B695919104}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D6D928A-AA0F-40F6-8930-47B695919104}.Release|Any CPU.Build.0 = Release|Any CPU + {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -160,6 +174,8 @@ Global {A19EC5EA-3E4F-47CD-A9B8-802663E9F489} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} {3649B470-E632-41F7-A7B9-5331B21B3560} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} + {1D6D928A-AA0F-40F6-8930-47B695919104} = {137019F4-2B62-4DD8-B2F8-0F5067205101} + {7435EFBA-471C-4BFB-A306-EB9CDF375585} = {137019F4-2B62-4DD8-B2F8-0F5067205101} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0E72B357-9E1E-43B5-9868-8D2B74CB2AF0} diff --git a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs new file mode 100644 index 0000000000..7232316249 --- /dev/null +++ b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs @@ -0,0 +1,47 @@ +using Microsoft.CodeAnalysis; +using Nox.Solution; + +namespace Nox.Generator.Common; + +public class ServiceCollectionExtensionGenerator +{ + public static void Generate(SourceProductionContext context, NoxSolution solution) + { + context.CancellationToken.ThrowIfCancellationRequested(); + + var code = new CodeBuilder($"NoxServiceCollectionExtension.g.cs", context); + + code.AppendLine("using Microsoft.EntityFrameworkCore;"); + code.AppendLine("using Nox;"); + code.AppendLine("using Nox.DatabaseProvider;"); + code.AppendLine("using Nox.DatabaseProvider.SqlServer;"); + code.AppendLine("using Nox.Types.EntityFramework.SqlServer;"); + code.AppendLine("using Nox.Types.EntityFramework.vNext;"); + code.AppendLine("using SampleWebApp.Infrastructure.Persistence;"); + code.AppendLine(); + + code.AppendLine("public static class NoxServiceCollectionExtension"); + code.StartBlock(); + code.AppendLine("public static IServiceCollection AddNox(this IServiceCollection services)"); + code.StartBlock(); + code.AppendLine("services.AddNoxLib();"); + if (solution.Infrastructure is { Persistence.DatabaseServer: not null }) + { + var dbContextName = $"{solution.Name}DbContext"; + code.AppendLine($"services.AddSingleton>();"); + code.AppendLine("services.AddSingleton();"); + code.AppendLine("services.AddSingleton();"); + code.AppendLine($"services.AddDbContext<{dbContextName}>();"); + code.AppendLine("var tmpProvider = services.BuildServiceProvider();"); + code.AppendLine($"var dbContext = tmpProvider.GetRequiredService<{dbContextName}>();"); + code.AppendLine("dbContext.Database.EnsureCreated();"); + } + + code.AppendLine("return services;"); + code.EndBlock(); + code.EndBlock(); + + code.GenerateSourceCode(); + + } +} \ No newline at end of file diff --git a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs index ac12826106..f5893a1af7 100644 --- a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs +++ b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs @@ -1,13 +1,12 @@ -using System.Text; -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Nox.Generator.Common; using Nox.Solution; -namespace Nox.Generator; +namespace Nox.Generator.Infrastructure.Persistence.DbContextGenerator; -internal class DbContextGenerator +internal static class DbContextGenerator { - public static void Generate(SourceProductionContext context, string solutionNameSpace, NoxSolution solution) + public static void Generate(SourceProductionContext context, NoxSolution solution) { context.CancellationToken.ThrowIfCancellationRequested(); @@ -21,73 +20,107 @@ public static void Generate(SourceProductionContext context, string solutionName var code = new CodeBuilder($"{dbContextName}.g.cs",context); // Namespace + AddUsing(code, solution.Name); + AddClass(code, solution, dbContextName); + + code.GenerateSourceCode(); + + } + + private static void AddUsing(CodeBuilder code, string solutionNameSpace) + { code.AppendLine(@"using Microsoft.EntityFrameworkCore;"); + code.AppendLine(@"using Nox.DatabaseProvider;"); code.AppendLine(@"using Nox.Solution;"); code.AppendLine(@"using Nox.Types.EntityFramework.vNext;"); code.AppendLine(@"using SampleWebApp.Domain;"); code.AppendLine(); code.AppendLine($"namespace {solutionNameSpace}.Infrastructure.Persistence;"); code.AppendLine(); + } + private static void AddClass(CodeBuilder code, NoxSolution solution, string dbContextName) + { code.AppendLine($"public partial class {dbContextName} : DbContext"); // Class code.StartBlock(); - code.AppendLine($"private NoxSolution _noxSolution {{ get; set; }}"); - code.AppendLine($"private INoxDatabaseConfigurator _databaseConfigurator {{ get; set; }}"); - code.AppendLine(); - - // Constructor - code.AppendLine($"public {dbContextName}("); - - // Constructor content - code.Indent(); - code.AppendLine($"DbContextOptions<{dbContextName}> options,"); - code.AppendLine($"NoxSolution noxSolution,"); - code.AppendLine($"INoxDatabaseConfigurator databaseConfigurator"); - code.AppendLine($") : base(options)"); - code.UnIndent(); - code.AppendLine($"{{"); - code.Indent(); - code.AppendLine($"_noxSolution = noxSolution;"); - code.AppendLine($"_databaseConfigurator = databaseConfigurator;"); - code.UnIndent(); - code.AppendLine($"}}"); - code.AppendLine(); - - foreach (var entity in solution.Domain.Entities) - { - code.AppendLine($"public DbSet<{entity.Name}> {entity.PluralName} {{get; set;}} = null!;"); - code.AppendLine(); - } - - // Method content - code.AppendLine(@" - public static void RegisterDbContext(IServiceCollection services) - { - services.AddDbContext<" + dbContextName + @">(); + code.AppendLine("private readonly NoxSolution _noxSolution;"); + code.AppendLine("private readonly INoxDatabaseConfigurator _databaseConfigurator;"); + code.AppendLine("private readonly INoxDatabaseProvider _dbProvider;"); + code.AppendLine(); + + code.AppendLine($"public {dbContextName}("); + code.AppendLine($" DbContextOptions<{dbContextName}> options,"); + code.AppendLine(" NoxSolution noxSolution,"); + code.AppendLine(" INoxDatabaseConfigurator databaseConfigurator,"); + code.AppendLine(" INoxDatabaseProvider databaseProvider"); + code.AppendLine(") : base(options)"); + code.StartBlock(); + code.AppendLine(" _noxSolution = noxSolution;"); + code.AppendLine(" _databaseConfigurator = databaseConfigurator;"); + code.AppendLine(" _dbProvider = databaseProvider;"); + code.EndBlock(); + code.AppendLine(); + + AddDbSets(code, solution); + + AddOnConfiguring(code, solution.Name); + + AddOnModelCreating(code, solution.Name); + + // End class + code.EndBlock(); + code.AppendLine(); } - protected override void OnModelCreating(ModelBuilder modelBuilder) + private static void AddDbSets(CodeBuilder code, NoxSolution solution) { - if (_noxSolution.Domain != null) + foreach (var entity in solution.Domain!.Entities) { - foreach (var entity in _noxSolution.Domain.Entities) - { - var type = Type.GetType(""" + solutionNameSpace + @".Domain."" + entity.Name); - - if (type != null) - { - _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); - } - } - - base.OnModelCreating(modelBuilder); + AddDbSet(code, entity); } } -} -"); - code.GenerateSourceCode(); + + private static void AddDbSet(CodeBuilder code, Entity entity) + { + code.AppendLine($"public DbSet<{entity.Name}> {entity.PluralName} {{get; set;}} = null!;"); + code.AppendLine(); + } + + private static void AddOnConfiguring(CodeBuilder code, string solutionName) + { + code.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)"); + code.StartBlock(); + code.AppendLine("base.OnConfiguring(optionsBuilder);"); + code.AppendLine("if (_noxSolution.Infrastructure is { Persistence.DatabaseServer: not null })"); + code.StartBlock(); + code.AppendLine($"_dbProvider.ConfigureDbContext(optionsBuilder, \"{solutionName}\", _noxSolution.Infrastructure!.Persistence.DatabaseServer); "); + code.EndBlock(); + code.EndBlock(); + code.AppendLine(); + } + + private static void AddOnModelCreating(CodeBuilder code, string solutionName) + { + code.AppendLine("protected override void OnModelCreating(ModelBuilder modelBuilder)"); + code.StartBlock(); + code.AppendLine("base.OnModelCreating(modelBuilder);"); + code.AppendLine("if (_noxSolution.Domain != null)"); + code.StartBlock(); + code.AppendLine("foreach (var entity in _noxSolution.Domain.Entities)"); + code.StartBlock(); + code.AppendLine($"var type = Type.GetType(\"{solutionName}.Domain.\" + entity.Name);"); + code.AppendLine(); + code.AppendLine("if (type != null)"); + code.StartBlock(); + code.AppendLine("_databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity);"); + code.EndBlock(); + code.EndBlock(); + code.AppendLine(); + code.EndBlock(); + code.EndBlock(); } } + diff --git a/src/Nox.Generator/Nox.Generator.cs b/src/Nox.Generator/Nox.Generator.cs index 2de46c4665..778671c41a 100644 --- a/src/Nox.Generator/Nox.Generator.cs +++ b/src/Nox.Generator/Nox.Generator.cs @@ -1,5 +1,4 @@ -using FluentValidation; -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Text; using Nox.Generator.Application.DtoGenerator; using Nox.Generator.Application.EventGenerator; @@ -14,6 +13,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using Nox.Generator.Infrastructure.Persistence.DbContextGenerator; using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -59,6 +59,8 @@ private void GenerateSource(SourceProductionContext context, ImmutableArray<(str if (TryGetGeneratorConfig(noxYamls, out var generate) && TryGetNoxSolution(noxYamls, out var solution)) { var solutionNameSpace = solution.Name; + + ServiceCollectionExtensionGenerator.Generate(context, solution); if (generate.Domain) { @@ -77,7 +79,7 @@ private void GenerateSource(SourceProductionContext context, ImmutableArray<(str if (generate.Infrastructure) { - DbContextGenerator.Generate(context, solutionNameSpace, solution); + DbContextGenerator.Generate(context, solution); } if (generate.Presentation) diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index a0549c9f7d..6cbc88b5bb 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,6 +36,7 @@ + diff --git a/src/SampleWebApp/Examples/CountriesController.cs b/src/SampleWebApp/Examples/CountriesController.cs index e91532e0f2..f273b8dafc 100644 --- a/src/SampleWebApp/Examples/CountriesController.cs +++ b/src/SampleWebApp/Examples/CountriesController.cs @@ -16,9 +16,9 @@ namespace SampleWebApp.Examples; public class CountriesController : ODataController { - SampleWebAppDbContextExample _databaseContext; + SampleWebAppDbContext _databaseContext; - public CountriesController(SampleWebAppDbContextExample databaseContext) + public CountriesController(SampleWebAppDbContext databaseContext) { _databaseContext = databaseContext; } diff --git a/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs b/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs deleted file mode 100644 index 83eb2c9f20..0000000000 --- a/src/SampleWebApp/Examples/SampleWebAppDbContextExample.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Nox.Solution; -using Nox.Types.EntityFramework.vNext; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; - -namespace SampleWebApp.Examples; - -public class SampleWebAppDbContextExample : DbContext -{ - private NoxSolution _noxSolution { get; set; } - private INoxDatabaseConfigurator _databaseConfigurator { get; set; } - -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - public SampleWebAppDbContextExample( - DbContextOptions options, - NoxSolution noxSolution, - INoxDatabaseConfigurator databaseConfigurator - ) : base(options) -#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - { - _noxSolution = noxSolution; - _databaseConfigurator = databaseConfigurator; - } - - public DbSet Countries; - - public DbSet Currencies; - - public DbSet Stores; - - public DbSet CountryLocalNames; - - public static void RegisterDbContext(IServiceCollection services) - { - services.AddDbContext(); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - if (_noxSolution.Domain != null) - { - foreach (var entity in _noxSolution.Domain.Entities) - { - var type = Type.GetType("SampleWebApp.Domain." + entity.Name); - - if (type != null) - { - _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); - } - } - - base.OnModelCreating(modelBuilder); - } - } -} \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs b/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs new file mode 100644 index 0000000000..a127cd6a0a --- /dev/null +++ b/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Xunit; + +namespace Nox.Generator.Tests.Infrastructure.Persistence; + +public class DatabaseServerTests : IClassFixture +{ + private readonly GeneratorFixture _fixture; + + public DatabaseServerTests(GeneratorFixture fixture) + { + _fixture = fixture; + } + + + [Fact] + public void Can_generate_database_server_files() + { + var path = "files/yaml/infrastructure/"; + var additionalFiles = new List(); + additionalFiles.Add(new AdditionalSourceText(File.ReadAllText($"./{path}generator.nox.yaml"), $"{path}/generator.nox.yaml")); + additionalFiles.Add(new AdditionalSourceText(File.ReadAllText($"./{path}database-server.solution.nox.yaml"), $"{path}/database-server.solution.nox.yaml")); + + // trackIncrementalGeneratorSteps allows to report info about each step of the generator + GeneratorDriver driver = CSharpGeneratorDriver.Create( + generators: new[] { _fixture.TestGenerator }, + additionalTexts: additionalFiles, + driverOptions: new GeneratorDriverOptions(default, trackIncrementalGeneratorSteps: true)); + + // Run the generator + driver = driver.RunGenerators(_fixture.TestCompilation!); + + // Assert the driver doesn't recompute the output + var result = driver.GetRunResult().Results.Single(); + var allOutputs = result.TrackedOutputSteps.SelectMany(outputStep => outputStep.Value).SelectMany(output => output.Outputs); + Assert.NotNull(allOutputs); + Assert.Single(allOutputs); + + var generatedSources = result.GeneratedSources; + Assert.Equal(6, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "EntityBase.g.cs"), "EntityBase.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "AuditableEntityBase.g.cs"), "AuditableEntityBase.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "Country.g.cs"), "Country.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "SampleWebAppDbContext.g.cs"), "SampleWebAppDbContext.g.cs not generated"); + //can further extend this test to verify contents of source files. + } +} \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index 6f5f7daf9d..2b0c80e286 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -64,6 +64,12 @@ Always + + Always + + + Always + diff --git a/tests/Nox.Generator.Tests/files/yaml/infrastructure/database-server.solution.nox.yaml b/tests/Nox.Generator.Tests/files/yaml/infrastructure/database-server.solution.nox.yaml new file mode 100644 index 0000000000..342041141f --- /dev/null +++ b/tests/Nox.Generator.Tests/files/yaml/infrastructure/database-server.solution.nox.yaml @@ -0,0 +1,59 @@ +name: SampleWebApp + +description: Sample Nox solution yaml configuration + +domain: + + entities: + + - name: Country + description: The list of countries + + keys: + + - name: Id + type: text + textTypeOptions: + isUnicode: false + minLength: 2 + maxLength: 2 + + attributes: + + - name: Name + description: The country's common name + type: text + textTypeOptions: + minLength: 4 + maxLength: 63 + isRequired: true + + - name: FormalName + description: The country's official name + type: text + textTypeOptions: + minLength: 4 + maxLength: 63 + isRequired: true + +infrastructure: + + persistence: + + databaseServer: + name: SampleCurrencyDb + + # Sql Server + serverUri: localhost + provider: sqlServer + port: 1433 + user: sa + password: Developer*123 + options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; + +# bug in Nox.Solution cannot create infrastructure without integrationEventServer + messaging: + integrationEventServer: + name: SampleEventServer + provider: inMemory + serverUri: localhost \ No newline at end of file diff --git a/tests/Nox.Generator.Tests/files/yaml/infrastructure/generator.nox.yaml b/tests/Nox.Generator.Tests/files/yaml/infrastructure/generator.nox.yaml new file mode 100644 index 0000000000..4ec266d6f6 --- /dev/null +++ b/tests/Nox.Generator.Tests/files/yaml/infrastructure/generator.nox.yaml @@ -0,0 +1,22 @@ +# +# generator.nox.yaml +# +# This file configures which layers of code the Nox generator will generate in this project. +# +# Please mark this as a C# analyzer addition file by including the following in your .csproj +# +# +# +# + +# Genrates momain models, events and related types +domain: true + +# Generates application logic and events +application: false + +# Generates persistence, DbContext and model configuration and mapping +infrastructure: true + +# Generates APi's and UI's +presentation: false From 1de905108e2c4397cfccc7ce5d15387378c4b010 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 07:06:20 +0200 Subject: [PATCH 02/18] moved docker-compose to project root --- docker-compose.elastic.yml | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 docker-compose.elastic.yml diff --git a/docker-compose.elastic.yml b/docker-compose.elastic.yml new file mode 100644 index 0000000000..f6c87420d7 --- /dev/null +++ b/docker-compose.elastic.yml @@ -0,0 +1,89 @@ +version: '2.2' +services: + apm-server: + image: docker.elastic.co/apm/apm-server:7.17.10 + depends_on: + elasticsearch: + condition: service_healthy + kibana: + condition: service_healthy + cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"] + cap_drop: ["ALL"] + ports: + - 8200:8200 + networks: + - elastic + command: > + apm-server -e + -E apm-server.rum.enabled=true + -E setup.kibana.host=kibana:5601 + -E setup.template.settings.index.number_of_replicas=0 + -E apm-server.kibana.enabled=true + -E apm-server.kibana.host=kibana:5601 + -E output.elasticsearch.hosts=["elasticsearch:9200"] + -E apm-server.kibana.username=elastic + -E apm-server.kibana.password=$ELASTIC_PASSWORD + -E output.elasticsearch.username=elastic + -E output.elasticsearch.password=$ELASTIC_PASSWORD + healthcheck: + interval: 10s + retries: 12 + test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/ + + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10 + environment: + - bootstrap.memory_lock=true + - cluster.name=docker-cluster + - cluster.routing.allocation.disk.threshold_enabled=false + - discovery.type=single-node + - ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g + - xpack.security.enabled=$ELASTIC_SECURITY + - xpack.security.authc.api_key.enabled=true + - ELASTIC_PASSWORD=$ELASTIC_PASSWORD + ulimits: + memlock: + hard: -1 + soft: -1 + volumes: + - esdata:/usr/share/elasticsearch/data + ports: + - 9200:9200 + networks: + - elastic + healthcheck: + interval: 20s + retries: 10 + test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"' + + kibana: + image: docker.elastic.co/kibana/kibana:7.17.10 + depends_on: + elasticsearch: + condition: service_healthy + environment: + ELASTICSEARCH_URL: http://elasticsearch:9200 + ELASTICSEARCH_HOSTS: http://elasticsearch:9200 + ELASTICSEARCH_USERNAME: elastic + ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD + ports: + - 5601:5601 + networks: + - elastic + healthcheck: + test: + [ + "CMD-SHELL", + "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'", + ] + interval: 10s + timeout: 10s + retries: 120 + +volumes: + esdata: + driver: local + +networks: + elastic: + driver: bridge From 54f0e72f658586facec26a7e86f0a620c98ec3e5 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 07:07:48 +0200 Subject: [PATCH 03/18] improve docker compose files --- docker-compose.elastic.yml | 14 +++-- docker-compose.sqlServer.yml | 18 ++++++ docker-compose.yml | 107 +++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 docker-compose.sqlServer.yml create mode 100644 docker-compose.yml diff --git a/docker-compose.elastic.yml b/docker-compose.elastic.yml index f6c87420d7..6cada0c70c 100644 --- a/docker-compose.elastic.yml +++ b/docker-compose.elastic.yml @@ -1,6 +1,12 @@ -version: '2.2' +version: '3.7' + +volumes: + esdata: + driver: local + services: apm-server: + container_name: apm-server image: docker.elastic.co/apm/apm-server:7.17.10 depends_on: elasticsearch: @@ -31,6 +37,7 @@ services: test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/ elasticsearch: + container_name: elasticsearch image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10 environment: - bootstrap.memory_lock=true @@ -57,6 +64,7 @@ services: test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"' kibana: + container_name: kibana image: docker.elastic.co/kibana/kibana:7.17.10 depends_on: elasticsearch: @@ -80,10 +88,6 @@ services: timeout: 10s retries: 120 -volumes: - esdata: - driver: local - networks: elastic: driver: bridge diff --git a/docker-compose.sqlServer.yml b/docker-compose.sqlServer.yml new file mode 100644 index 0000000000..1b08827ed4 --- /dev/null +++ b/docker-compose.sqlServer.yml @@ -0,0 +1,18 @@ +version: '3.7' + +volumes: + sqlserver: + +services: + sqlserver: + container_name: sqlserver_container + image: "mcr.microsoft.com/azure-sql-edge:latest" + user: root + ports: + - "1433:1433" + environment: + SA_PASSWORD: "Developer*123" + ACCEPT_EULA: "Y" + MSSQL_PID: "Developer" + volumes: + - sqlserver:/var/opt/mssql/data \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..0f214e351b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,107 @@ +version: '3.7' + +volumes: + sqlserver: + esdata: + driver: local + +services: + sqlserver: + container_name: sqlserver_container + image: "mcr.microsoft.com/azure-sql-edge:latest" + user: root + ports: + - "1433:1433" + environment: + SA_PASSWORD: "Developer*123" + ACCEPT_EULA: "Y" + MSSQL_PID: "Developer" + volumes: + - sqlserver:/var/opt/mssql/data + + apm-server: + container_name: apm-server + image: docker.elastic.co/apm/apm-server:7.17.10 + depends_on: + elasticsearch: + condition: service_healthy + kibana: + condition: service_healthy + cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"] + cap_drop: ["ALL"] + ports: + - 8200:8200 + networks: + - elastic + command: > + apm-server -e + -E apm-server.rum.enabled=true + -E setup.kibana.host=kibana:5601 + -E setup.template.settings.index.number_of_replicas=0 + -E apm-server.kibana.enabled=true + -E apm-server.kibana.host=kibana:5601 + -E output.elasticsearch.hosts=["elasticsearch:9200"] + -E apm-server.kibana.username=elastic + -E apm-server.kibana.password=$ELASTIC_PASSWORD + -E output.elasticsearch.username=elastic + -E output.elasticsearch.password=$ELASTIC_PASSWORD + healthcheck: + interval: 10s + retries: 12 + test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/ + + elasticsearch: + container_name: elasticsearch + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10 + environment: + - bootstrap.memory_lock=true + - cluster.name=docker-cluster + - cluster.routing.allocation.disk.threshold_enabled=false + - discovery.type=single-node + - ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g + - xpack.security.enabled=$ELASTIC_SECURITY + - xpack.security.authc.api_key.enabled=true + - ELASTIC_PASSWORD=$ELASTIC_PASSWORD + ulimits: + memlock: + hard: -1 + soft: -1 + volumes: + - esdata:/usr/share/elasticsearch/data + ports: + - 9200:9200 + networks: + - elastic + healthcheck: + interval: 20s + retries: 10 + test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"' + + kibana: + container_name: kibana + image: docker.elastic.co/kibana/kibana:7.17.10 + depends_on: + elasticsearch: + condition: service_healthy + environment: + ELASTICSEARCH_URL: http://elasticsearch:9200 + ELASTICSEARCH_HOSTS: http://elasticsearch:9200 + ELASTICSEARCH_USERNAME: elastic + ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD + ports: + - 5601:5601 + networks: + - elastic + healthcheck: + test: + [ + "CMD-SHELL", + "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'", + ] + interval: 10s + timeout: 10s + retries: 120 + +networks: + elastic: + driver: bridge \ No newline at end of file From 4eecfc5a1044a5be262cd99683e691025e2ab3cf Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 07:46:17 +0200 Subject: [PATCH 04/18] - docker compose update --- docs/docker/docker-compose.elastic.yml | 89 -------------------------- 1 file changed, 89 deletions(-) delete mode 100644 docs/docker/docker-compose.elastic.yml diff --git a/docs/docker/docker-compose.elastic.yml b/docs/docker/docker-compose.elastic.yml deleted file mode 100644 index f6c87420d7..0000000000 --- a/docs/docker/docker-compose.elastic.yml +++ /dev/null @@ -1,89 +0,0 @@ -version: '2.2' -services: - apm-server: - image: docker.elastic.co/apm/apm-server:7.17.10 - depends_on: - elasticsearch: - condition: service_healthy - kibana: - condition: service_healthy - cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"] - cap_drop: ["ALL"] - ports: - - 8200:8200 - networks: - - elastic - command: > - apm-server -e - -E apm-server.rum.enabled=true - -E setup.kibana.host=kibana:5601 - -E setup.template.settings.index.number_of_replicas=0 - -E apm-server.kibana.enabled=true - -E apm-server.kibana.host=kibana:5601 - -E output.elasticsearch.hosts=["elasticsearch:9200"] - -E apm-server.kibana.username=elastic - -E apm-server.kibana.password=$ELASTIC_PASSWORD - -E output.elasticsearch.username=elastic - -E output.elasticsearch.password=$ELASTIC_PASSWORD - healthcheck: - interval: 10s - retries: 12 - test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/ - - elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10 - environment: - - bootstrap.memory_lock=true - - cluster.name=docker-cluster - - cluster.routing.allocation.disk.threshold_enabled=false - - discovery.type=single-node - - ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g - - xpack.security.enabled=$ELASTIC_SECURITY - - xpack.security.authc.api_key.enabled=true - - ELASTIC_PASSWORD=$ELASTIC_PASSWORD - ulimits: - memlock: - hard: -1 - soft: -1 - volumes: - - esdata:/usr/share/elasticsearch/data - ports: - - 9200:9200 - networks: - - elastic - healthcheck: - interval: 20s - retries: 10 - test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"' - - kibana: - image: docker.elastic.co/kibana/kibana:7.17.10 - depends_on: - elasticsearch: - condition: service_healthy - environment: - ELASTICSEARCH_URL: http://elasticsearch:9200 - ELASTICSEARCH_HOSTS: http://elasticsearch:9200 - ELASTICSEARCH_USERNAME: elastic - ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD - ports: - - 5601:5601 - networks: - - elastic - healthcheck: - test: - [ - "CMD-SHELL", - "curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'", - ] - interval: 10s - timeout: 10s - retries: 120 - -volumes: - esdata: - driver: local - -networks: - elastic: - driver: bridge From 84afbef88601260837003ed8463a748dce0fd1f9 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 08:08:25 +0200 Subject: [PATCH 05/18] - docker-compose improve - database server fix in sample.solution.nox.yaml --- .nox/design/sample.solution.nox.yaml | 7 +++-- docker-compose.elastic.yml | 10 +++---- docker-compose.yml | 12 ++++---- src/Nox.Generator/Nox.Generator.csproj | 6 ---- .../Extensions/ServiceCollectionExtension.cs | 5 ++-- src/Nox.Lib/Nox.Lib.csproj | 2 ++ .../SampleWebAppDbContext.g.cs | 29 ++++++++++++------- 7 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.nox/design/sample.solution.nox.yaml b/.nox/design/sample.solution.nox.yaml index 2fc48bbe99..24083ebc61 100644 --- a/.nox/design/sample.solution.nox.yaml +++ b/.nox/design/sample.solution.nox.yaml @@ -412,11 +412,12 @@ infrastructure: name: SampleCurrencyDb # Sql Server - serverUri: sqlserver.iwgplc.com + serverUri: localhost provider: sqlServer port: 1433 - user: sqluser - password: sqlpassword + user: sa + password: Developer*123 + options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; ### Postgres #provider: postgres diff --git a/docker-compose.elastic.yml b/docker-compose.elastic.yml index 6cada0c70c..1d09e542bb 100644 --- a/docker-compose.elastic.yml +++ b/docker-compose.elastic.yml @@ -28,9 +28,9 @@ services: -E apm-server.kibana.host=kibana:5601 -E output.elasticsearch.hosts=["elasticsearch:9200"] -E apm-server.kibana.username=elastic - -E apm-server.kibana.password=$ELASTIC_PASSWORD + -E apm-server.kibana.password=Developer*123 -E output.elasticsearch.username=elastic - -E output.elasticsearch.password=$ELASTIC_PASSWORD + -E output.elasticsearch.password=Developer*123 healthcheck: interval: 10s retries: 12 @@ -45,9 +45,9 @@ services: - cluster.routing.allocation.disk.threshold_enabled=false - discovery.type=single-node - ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g - - xpack.security.enabled=$ELASTIC_SECURITY + - xpack.security.enabled=true - xpack.security.authc.api_key.enabled=true - - ELASTIC_PASSWORD=$ELASTIC_PASSWORD + - ELASTIC_PASSWORD=Developer*123 ulimits: memlock: hard: -1 @@ -73,7 +73,7 @@ services: ELASTICSEARCH_URL: http://elasticsearch:9200 ELASTICSEARCH_HOSTS: http://elasticsearch:9200 ELASTICSEARCH_USERNAME: elastic - ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD + ELASTICSEARCH_PASSWORD: Developer*123 ports: - 5601:5601 networks: diff --git a/docker-compose.yml b/docker-compose.yml index 0f214e351b..530e8ed08f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -42,9 +42,9 @@ services: -E apm-server.kibana.host=kibana:5601 -E output.elasticsearch.hosts=["elasticsearch:9200"] -E apm-server.kibana.username=elastic - -E apm-server.kibana.password=$ELASTIC_PASSWORD + -E apm-server.kibana.password=Developer*123 -E output.elasticsearch.username=elastic - -E output.elasticsearch.password=$ELASTIC_PASSWORD + -E output.elasticsearch.password=Developer*123 healthcheck: interval: 10s retries: 12 @@ -59,9 +59,9 @@ services: - cluster.routing.allocation.disk.threshold_enabled=false - discovery.type=single-node - ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g - - xpack.security.enabled=$ELASTIC_SECURITY + - xpack.security.enabled=true - xpack.security.authc.api_key.enabled=true - - ELASTIC_PASSWORD=$ELASTIC_PASSWORD + - ELASTIC_PASSWORD=Developer*123 ulimits: memlock: hard: -1 @@ -87,7 +87,7 @@ services: ELASTICSEARCH_URL: http://elasticsearch:9200 ELASTICSEARCH_HOSTS: http://elasticsearch:9200 ELASTICSEARCH_USERNAME: elastic - ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD + ELASTICSEARCH_PASSWORD: Developer*123 ports: - 5601:5601 networks: @@ -104,4 +104,4 @@ services: networks: elastic: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/src/Nox.Generator/Nox.Generator.csproj b/src/Nox.Generator/Nox.Generator.csproj index 4e98ee5f64..c08a6bf211 100644 --- a/src/Nox.Generator/Nox.Generator.csproj +++ b/src/Nox.Generator/Nox.Generator.csproj @@ -27,9 +27,6 @@ - - - @@ -47,9 +44,6 @@ - - - diff --git a/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs b/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs index e4d43534fd..96d693ccde 100644 --- a/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs +++ b/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs @@ -1,5 +1,6 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; +using Nox.DatabaseProvider; using Nox.Solution; namespace Nox; @@ -17,10 +18,10 @@ public static NoxSolution Solution } } - public static IServiceCollection AddNox(this IServiceCollection services) + public static IServiceCollection AddNoxLib(this IServiceCollection services) { services.AddSingleton(Solution); - + return services; } diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index 6cbc88b5bb..bf161e439a 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,12 +36,14 @@ + + diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs index 8cca3953cd..2a70b3bf20 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs @@ -3,6 +3,7 @@ #nullable enable using Microsoft.EntityFrameworkCore; +using Nox.DatabaseProvider; using Nox.Solution; using Nox.Types.EntityFramework.vNext; using SampleWebApp.Domain; @@ -11,17 +12,20 @@ namespace SampleWebApp.Infrastructure.Persistence; public partial class SampleWebAppDbContext : DbContext { - private NoxSolution _noxSolution { get; set; } - private INoxDatabaseConfigurator _databaseConfigurator { get; set; } + private readonly NoxSolution _noxSolution; + private readonly INoxDatabaseConfigurator _databaseConfigurator; + private readonly INoxDatabaseProvider _dbProvider; public SampleWebAppDbContext( DbContextOptions options, NoxSolution noxSolution, - INoxDatabaseConfigurator databaseConfigurator - ) : base(options) + INoxDatabaseConfigurator databaseConfigurator, + INoxDatabaseProvider databaseProvider + ) : base(options) { - _noxSolution = noxSolution; - _databaseConfigurator = databaseConfigurator; + _noxSolution = noxSolution; + _databaseConfigurator = databaseConfigurator; + _dbProvider = databaseProvider; } public DbSet Countries {get; set;} = null!; @@ -32,14 +36,18 @@ INoxDatabaseConfigurator databaseConfigurator public DbSet CountryLocalNames {get; set;} = null!; - - public static void RegisterDbContext(IServiceCollection services) + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - services.AddDbContext(); + base.OnConfiguring(optionsBuilder); + if (_noxSolution.Infrastructure is { Persistence.DatabaseServer: not null }) + { + _dbProvider.ConfigureDbContext(optionsBuilder, "SampleWebApp", _noxSolution.Infrastructure!.Persistence.DatabaseServer); + } } - + protected override void OnModelCreating(ModelBuilder modelBuilder) { + base.OnModelCreating(modelBuilder); if (_noxSolution.Domain != null) { foreach (var entity in _noxSolution.Domain.Entities) @@ -52,7 +60,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) } } - base.OnModelCreating(modelBuilder); } } } From d3623f78b8aa833f6e4fa4d855eb8ca9f0eb9814 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 08:38:00 +0200 Subject: [PATCH 06/18] - regenerated files --- .nox/design/sample.solution.nox.yaml | 2 +- .../AuditableEntityBase.g.cs | 40 ----- .../CountriesApiController.g.cs | 58 -------- .../CountriesController.g.cs | 140 ------------------ .../Country.g.cs | 90 ----------- .../CountryDto.g.cs | 23 --- .../CountryInfo.g.cs | 26 ---- .../CountryLocalNames.g.cs | 20 --- .../CountryLocalNamesController.g.cs | 140 ------------------ .../CountryNameChangedAppEvent.g.cs | 28 ---- .../CountryNameUpdatedEvent.g.cs | 27 ---- .../CurrenciesController.g.cs | 140 ------------------ .../Currency.g.cs | 32 ---- .../EntityBase.g.cs | 18 --- .../Generator.g.cs | 11 -- .../GetCountriesByContinentQuery.g.cs | 32 ---- .../ODataConfiguration.g.cs | 34 ----- .../SampleWebAppDbContext.g.cs | 66 --------- .../Nox.Generator.NoxCodeGenerator/Store.g.cs | 30 ---- .../StoresController.g.cs | 140 ------------------ .../UpdatePopulationStatistics.g.cs | 20 --- ...opulationStatisticsCommandHandlerBase.g.cs | 51 ------- 22 files changed, 1 insertion(+), 1167 deletions(-) delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs diff --git a/.nox/design/sample.solution.nox.yaml b/.nox/design/sample.solution.nox.yaml index 24083ebc61..6a5a1a6932 100644 --- a/.nox/design/sample.solution.nox.yaml +++ b/.nox/design/sample.solution.nox.yaml @@ -430,7 +430,7 @@ infrastructure: provider: azureRedis serverUri: redis.iwgplc.com user: RedisUser - password: RedisPassword + password: RedisPassword*123 searchServer: name: SampleSearch diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs deleted file mode 100644 index a5908d5ce9..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Generated - -#nullable enable - -using System; - -namespace SampleWebApp.Domain; - -public partial class AuditableEntityBase -{ - /// - /// The date and time when this entity was first created (in Coordinated Universal Time). - /// - public DateTime CreatedAtUtc {get; set;} - - /// - /// The user that created the entity. - /// - public string? CreatedBy {get; set;} - - /// - /// The date and time when this entity was last updated (in Coordinated Universal Time). - /// - public DateTime? UpdatedAtUtc {get; set;} - - /// - /// The user that last updated the entity. - /// - public string? UpdatedBy {get; set;} - - /// - /// The date and time when this entity was deleted (in Coordinated Universal Time). - /// - public DateTime? DeletedAtUtc {get; set;} - - /// - /// The user that deleted the entity. - /// - public string? DeletedBy {get; set;} -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs deleted file mode 100644 index c35ca25a10..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using Microsoft.AspNetCore.Mvc; -using SampleWebApp.Application; -using SampleWebApp.Application.DataTransferObjects; - -namespace SampleWebApp.Presentation.Rest; - -/// -/// Controller for Country entity. The list of countries. -/// -[ApiController] -[Route("Countries")] -public partial class CountriesApiController : ControllerBase -{ - - /// - /// Returns a list of countries for a given continent. - /// - protected GetCountriesByContinentQuery GetCountriesByContinent { get; set; } = null!; - - /// - /// Instructs the service to collect updated population statistics. - /// - protected UpdatePopulationStatisticsCommandHandlerBase UpdatePopulationStatistics { get; set; } = null!; - - public CountriesApiController( - GetCountriesByContinentQuery getCountriesByContinent, - UpdatePopulationStatisticsCommandHandlerBase updatePopulationStatistics - ) - { - GetCountriesByContinent = getCountriesByContinent; - UpdatePopulationStatistics = updatePopulationStatistics; - } - - /// - /// Returns a list of countries for a given continent. - /// - [HttpGet("GetCountriesByContinent")] - public async Task GetCountriesByContinentAsync(Text continentName) - { - var result = await GetCountriesByContinent.ExecuteAsync(continentName); - return Results.Ok(result); - } - - /// - /// Instructs the service to collect updated population statistics. - /// - [HttpPost("UpdatePopulationStatistics")] - public async Task UpdatePopulationStatisticsAsync(UpdatePopulationStatistics command) - { - var result = await UpdatePopulationStatistics.ExecuteAsync(command); - return result.IsSuccess ? Results.Ok(result) : Results.BadRequest(result); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs deleted file mode 100644 index 4235f60732..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CountriesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CountriesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Countries); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Countries.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Country country) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Countries.Add(country); - - await _databaseContext.SaveChangesAsync(); - - return Created(country); - } - - public async Task Put([FromRoute] string key, [FromBody] Country updatedCountry) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCountry.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCountry).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCountry); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta country) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Countries.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - country.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CountryExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Countries.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var country = await _databaseContext.Countries.FindAsync(parsedKey); - if (country == null) - { - return NotFound(); - } - - _databaseContext.Countries.Remove(country); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs deleted file mode 100644 index 6805e60b72..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The list of countries. -/// -public partial class Country : AuditableEntityBase -{ - - /// - /// (Optional) - /// - public Text Id { get; set; } = null!; - - /// - /// The country's common name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// The country's official name (required). - /// - public Text FormalName { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-3 code (required). - /// - public Text AlphaCode3 { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-2 code (required). - /// - public Text AlphaCode2 { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-3 code (required). - /// - public Number NumericCode { get; set; } = null!; - - /// - /// The country's phone dialing codes (comma-delimited) (optional). - /// - public Text? DialingCodes { get; set; } = null!; - - /// - /// The capital city of the country (optional). - /// - public Text? Capital { get; set; } = null!; - - /// - /// Noun denoting the natives of the country (optional). - /// - public Text? Demonym { get; set; } = null!; - - /// - /// Country area in square kilometers (required). - /// - public Number AreaInSquareKilometres { get; set; } = null!; - - /// - /// The region the country is in (required). - /// - public Text GeoRegion { get; set; } = null!; - - /// - /// The sub-region the country is in (required). - /// - public Text GeoSubRegion { get; set; } = null!; - - /// - /// The world region the country is in (required). - /// - public Text GeoWorldRegion { get; set; } = null!; - - /// - /// The estimated population of the country (optional). - /// - public Number? Population { get; set; } = null!; - - /// - /// The top level internet domains regitered to the country (comma-delimited) (optional). - /// - public Text? TopLevelDomains { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs deleted file mode 100644 index fbafdeb1f7..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - -/// -/// Dto for country information. -/// -public partial class CountryDto : IDynamicDto -{ - - /// - /// The identity of the country, the Iso Alpha 2 code. - /// - public Text? Id { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs deleted file mode 100644 index 15779a0736..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - -public partial class CountryInfo : IDynamicDto -{ - - /// - /// The country's Id. - /// - public CountryCode2? CountryId { get; set; } = null!; - - - /// - /// The country name. - /// - public Text? CountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs deleted file mode 100644 index 4a0eb3b9e7..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The name of a country in other languages. -/// -public partial class CountryLocalNames : AuditableEntityBase -{ - - /// - /// (Optional) - /// - public Text Id { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs deleted file mode 100644 index 1cd291bdeb..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CountryLocalNamesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CountryLocalNamesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.CountryLocalNames); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.CountryLocalNames.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(CountryLocalNames countrylocalnames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.CountryLocalNames.Add(countrylocalnames); - - await _databaseContext.SaveChangesAsync(); - - return Created(countrylocalnames); - } - - public async Task Put([FromRoute] string key, [FromBody] CountryLocalNames updatedCountryLocalNames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCountryLocalNames.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCountryLocalNames).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryLocalNamesExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCountryLocalNames); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta countrylocalnames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - countrylocalnames.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryLocalNamesExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CountryLocalNamesExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.CountryLocalNames.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var countrylocalnames = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); - if (countrylocalnames == null) - { - return NotFound(); - } - - _databaseContext.CountryLocalNames.Remove(countrylocalnames); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs deleted file mode 100644 index 30d5eaea89..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateEvent - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.Events; - -/// -/// An application event raised when the name of a country changes. -/// -public partial class CountryNameChangedAppEvent : INoxApplicationEvent -{ - - /// - /// The identifier of the country. The Iso alpha 2 code. - /// - public CountryCode2? CountryId { get; set; } = null!; - - /// - /// The new name of the country. - /// - public Text? CountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs deleted file mode 100644 index 958ab8e47d..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DomainEventGenerator::GenerateEvent - -using Nox.Abstractions; -using Nox.Types; - -namespace SampleWebApp.Domain; - -/// -/// Raised when the name of a country is changes. -/// -public partial class CountryNameUpdatedEvent : INoxDomainEvent -{ - - /// - /// The identifier of the country. The Iso Alpha2 code of the country. - /// - public CountryCode2? CountryId { get; set; } = null!; - - /// - /// The new name of the country. - /// - public Text? NewCountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs deleted file mode 100644 index cb8ce6b2a0..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CurrenciesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CurrenciesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Currencies); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Currencies.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Currency currency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Currencies.Add(currency); - - await _databaseContext.SaveChangesAsync(); - - return Created(currency); - } - - public async Task Put([FromRoute] string key, [FromBody] Currency updatedCurrency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCurrency.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCurrency).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CurrencyExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCurrency); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta currency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Currencies.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - currency.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CurrencyExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CurrencyExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Currencies.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var currency = await _databaseContext.Currencies.FindAsync(parsedKey); - if (currency == null) - { - return NotFound(); - } - - _databaseContext.Currencies.Remove(currency); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs deleted file mode 100644 index 296af5eefa..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The list of currencies. -/// -public partial class Currency : AuditableEntityBase -{ - - /// - /// The currency's primary key / identifier (optional). - /// - public Text Id { get; set; } = null!; - - /// - /// The currency's name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// Currency is legal tender for ZeroOrMany Countries - /// - public List Countries { get; set; } = null!; - - public List CurrencyIsLegalTenderForCountry => Countries; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs deleted file mode 100644 index 61a67ada7e..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Generated - -#nullable enable - -using System; - -namespace SampleWebApp.Domain; - -/// -/// The base class for all domain entities. -/// -public partial class EntityBase -{ - /// - /// The state of the entity as at this date. - /// - public DateTime AsAt {get; set;} -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs deleted file mode 100644 index ecfc173c80..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Generated - -#nullable enable - -// Found files -> -// - currency.entity.nox.yaml -// - elastic.monitoring.nox.yaml -// - sample.solution.nox.yaml -// - store.entity.nox.yaml -// - generator.nox.yaml -// SUCCESS. diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs deleted file mode 100644 index 75759492bb..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; -using System.Threading.Tasks; -using SampleWebApp.Domain; -using SampleWebApp.Application.DataTransferObjects; -using SampleWebApp.Infrastructure.Persistence; - -namespace SampleWebApp.Application; - -/// -/// Returns a list of countries for a given continent. -/// -public abstract partial class GetCountriesByContinentQuery -{ - - /// - /// Represents the DB context. - /// - protected SampleWebAppDbContext DbContext { get; set; } = null!; - - public GetCountriesByContinentQuery( - SampleWebAppDbContext dbContext - ) - { - DbContext = dbContext; - } - public abstract Task> ExecuteAsync(Text continentName); -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs deleted file mode 100644 index edc2647ca2..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.OData; -using Microsoft.OData.ModelBuilder; -using SampleWebApp.Domain; -namespace SampleWebApp.Presentation.Api.OData; - -public partial class ODataConfiguration -{ - public static void Register(IServiceCollection services) - { - ODataModelBuilder builder = new ODataConventionModelBuilder(); - - builder.EntitySet("Countries"); - builder.EntitySet("Currencies"); - builder.EntitySet("Stores"); - builder.EntitySet("CountryLocalNames"); - - services.AddControllers() - .AddOData(options => options - .Select() - .Filter() - .OrderBy() - .Count() - .Expand() - .SkipToken() - .SetMaxTop(100) - .AddRouteComponents("api", builder.GetEdmModel()) - ); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs deleted file mode 100644 index 2a70b3bf20..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.EntityFrameworkCore; -using Nox.DatabaseProvider; -using Nox.Solution; -using Nox.Types.EntityFramework.vNext; -using SampleWebApp.Domain; - -namespace SampleWebApp.Infrastructure.Persistence; - -public partial class SampleWebAppDbContext : DbContext -{ - private readonly NoxSolution _noxSolution; - private readonly INoxDatabaseConfigurator _databaseConfigurator; - private readonly INoxDatabaseProvider _dbProvider; - - public SampleWebAppDbContext( - DbContextOptions options, - NoxSolution noxSolution, - INoxDatabaseConfigurator databaseConfigurator, - INoxDatabaseProvider databaseProvider - ) : base(options) - { - _noxSolution = noxSolution; - _databaseConfigurator = databaseConfigurator; - _dbProvider = databaseProvider; - } - - public DbSet Countries {get; set;} = null!; - - public DbSet Currencies {get; set;} = null!; - - public DbSet Stores {get; set;} = null!; - - public DbSet CountryLocalNames {get; set;} = null!; - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - base.OnConfiguring(optionsBuilder); - if (_noxSolution.Infrastructure is { Persistence.DatabaseServer: not null }) - { - _dbProvider.ConfigureDbContext(optionsBuilder, "SampleWebApp", _noxSolution.Infrastructure!.Persistence.DatabaseServer); - } - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - if (_noxSolution.Domain != null) - { - foreach (var entity in _noxSolution.Domain.Entities) - { - var type = Type.GetType("SampleWebApp.Domain." + entity.Name); - - if (type != null) - { - _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); - } - } - - } - } -} - diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs deleted file mode 100644 index 462ee71e47..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// Stores. -/// -public partial class Store : AuditableEntityBase -{ - - /// - /// Store Primary Key (optional). - /// - public Text Id { get; set; } = null!; - - /// - /// Store Name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// Physical Money in the Physical Store (required). - /// - public Money PhysicalMoney { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs deleted file mode 100644 index 9bbdf7fc66..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class StoresController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public StoresController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Stores); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Stores.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Store store) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Stores.Add(store); - - await _databaseContext.SaveChangesAsync(); - - return Created(store); - } - - public async Task Put([FromRoute] string key, [FromBody] Store updatedStore) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedStore.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedStore).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!StoreExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedStore); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta store) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Stores.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - store.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!StoreExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool StoreExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Stores.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var store = await _databaseContext.Stores.FindAsync(parsedKey); - if (store == null) - { - return NotFound(); - } - - _databaseContext.Stores.Remove(store); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs deleted file mode 100644 index 9b624fb469..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - - -/// -/// Instructs the service to collect updated population statistics. -/// -public partial class UpdatePopulationStatistics : IDynamicDto -{ - public CountryCode2? CountryCode { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs deleted file mode 100644 index a3cbbae4ea..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; -using Nox.Abstractions; -using SampleWebApp.Domain; -using SampleWebApp.Application.DataTransferObjects; -using SampleWebApp.Infrastructure.Persistence; - -namespace SampleWebApp.Application; - -/// -/// Instructs the service to collect updated population statistics. -/// -public abstract partial class UpdatePopulationStatisticsCommandHandlerBase -{ - - /// - /// Represents the DB context. - /// - protected SampleWebAppDbContext DbContext { get; set; } = null!; - - /// - /// Represents the Nox messenger. - /// - protected INoxMessenger Messenger { get; set; } = null!; - - public UpdatePopulationStatisticsCommandHandlerBase( - SampleWebAppDbContext dbContext, - INoxMessenger messenger - ) - { - DbContext = dbContext; - Messenger = messenger; - } - - /// - /// Executes UpdatePopulationStatistics. - /// - public abstract Task ExecuteAsync(UpdatePopulationStatistics command); - - /// - /// Sends CountryNameUpdatedEvent. - /// - public async Task SendCountryNameUpdatedEventDomainEventAsync(CountryNameUpdatedEvent domainEvent) - { - await Messenger.SendMessageAsync(new string[] { "Mediator" }, domainEvent); - } -} From fd8738efa2396785f69856b9d56d378374cd22c1 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 08:38:37 +0200 Subject: [PATCH 07/18] - new version of generated files --- .../AuditableEntityBase.g.cs | 40 +++++ .../CountriesApiController.g.cs | 58 ++++++++ .../CountriesController.g.cs | 140 ++++++++++++++++++ .../Country.g.cs | 90 +++++++++++ .../CountryDto.g.cs | 23 +++ .../CountryInfo.g.cs | 26 ++++ .../CountryLocalNames.g.cs | 20 +++ .../CountryLocalNamesController.g.cs | 140 ++++++++++++++++++ .../CountryNameChangedAppEvent.g.cs | 28 ++++ .../CountryNameUpdatedEvent.g.cs | 27 ++++ .../CurrenciesController.g.cs | 140 ++++++++++++++++++ .../Currency.g.cs | 32 ++++ .../EntityBase.g.cs | 18 +++ .../Generator.g.cs | 11 ++ .../GetCountriesByContinentQuery.g.cs | 32 ++++ .../NoxServiceCollectionExtension.g.cs | 27 ++++ .../ODataConfiguration.g.cs | 34 +++++ .../SampleWebAppDbContext.g.cs | 66 +++++++++ .../Nox.Generator.NoxCodeGenerator/Store.g.cs | 30 ++++ .../StoresController.g.cs | 140 ++++++++++++++++++ .../UpdatePopulationStatistics.g.cs | 20 +++ ...opulationStatisticsCommandHandlerBase.g.cs | 51 +++++++ 22 files changed, 1193 insertions(+) create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs create mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs new file mode 100644 index 0000000000..a5908d5ce9 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs @@ -0,0 +1,40 @@ +// Generated + +#nullable enable + +using System; + +namespace SampleWebApp.Domain; + +public partial class AuditableEntityBase +{ + /// + /// The date and time when this entity was first created (in Coordinated Universal Time). + /// + public DateTime CreatedAtUtc {get; set;} + + /// + /// The user that created the entity. + /// + public string? CreatedBy {get; set;} + + /// + /// The date and time when this entity was last updated (in Coordinated Universal Time). + /// + public DateTime? UpdatedAtUtc {get; set;} + + /// + /// The user that last updated the entity. + /// + public string? UpdatedBy {get; set;} + + /// + /// The date and time when this entity was deleted (in Coordinated Universal Time). + /// + public DateTime? DeletedAtUtc {get; set;} + + /// + /// The user that deleted the entity. + /// + public string? DeletedBy {get; set;} +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs new file mode 100644 index 0000000000..c35ca25a10 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs @@ -0,0 +1,58 @@ +// Generated + +#nullable enable + +using Nox.Types; +using Microsoft.AspNetCore.Mvc; +using SampleWebApp.Application; +using SampleWebApp.Application.DataTransferObjects; + +namespace SampleWebApp.Presentation.Rest; + +/// +/// Controller for Country entity. The list of countries. +/// +[ApiController] +[Route("Countries")] +public partial class CountriesApiController : ControllerBase +{ + + /// + /// Returns a list of countries for a given continent. + /// + protected GetCountriesByContinentQuery GetCountriesByContinent { get; set; } = null!; + + /// + /// Instructs the service to collect updated population statistics. + /// + protected UpdatePopulationStatisticsCommandHandlerBase UpdatePopulationStatistics { get; set; } = null!; + + public CountriesApiController( + GetCountriesByContinentQuery getCountriesByContinent, + UpdatePopulationStatisticsCommandHandlerBase updatePopulationStatistics + ) + { + GetCountriesByContinent = getCountriesByContinent; + UpdatePopulationStatistics = updatePopulationStatistics; + } + + /// + /// Returns a list of countries for a given continent. + /// + [HttpGet("GetCountriesByContinent")] + public async Task GetCountriesByContinentAsync(Text continentName) + { + var result = await GetCountriesByContinent.ExecuteAsync(continentName); + return Results.Ok(result); + } + + /// + /// Instructs the service to collect updated population statistics. + /// + [HttpPost("UpdatePopulationStatistics")] + public async Task UpdatePopulationStatisticsAsync(UpdatePopulationStatistics command) + { + var result = await UpdatePopulationStatistics.ExecuteAsync(command); + return result.IsSuccess ? Results.Ok(result) : Results.BadRequest(result); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs new file mode 100644 index 0000000000..4235f60732 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs @@ -0,0 +1,140 @@ +// Generated + +#nullable enable + +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Deltas; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; +using Microsoft.EntityFrameworkCore; +using SampleWebApp.Domain; +using SampleWebApp.Infrastructure.Persistence; +using Nox.Types; + +namespace SampleWebApp.Presentation.Api.OData; + +public class CountriesController : ODataController +{ + SampleWebAppDbContext _databaseContext; + + public CountriesController(SampleWebAppDbContext databaseContext) + { + _databaseContext = databaseContext; + } + + [EnableQuery] + public ActionResult> Get() + { + return Ok(_databaseContext.Countries); + } + + [EnableQuery] + public ActionResult Get([FromRoute] string key) + { + var parsedKey = Text.From(key); + var item = _databaseContext.Countries.SingleOrDefault(d => d.Id.Equals(parsedKey)); + + if (item == null) + { + return NotFound(); + } + return Ok(item); + } + + public async Task Post(Country country) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _databaseContext.Countries.Add(country); + + await _databaseContext.SaveChangesAsync(); + + return Created(country); + } + + public async Task Put([FromRoute] string key, [FromBody] Country updatedCountry) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + if (parsedKey != updatedCountry.Id) + { + return BadRequest(); + } + _databaseContext.Entry(updatedCountry).State = EntityState.Modified; + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CountryExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(updatedCountry); + } + + public async Task Patch([FromRoute] string key, [FromBody] Delta country) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + var entity = await _databaseContext.Countries.FindAsync(parsedKey); + if (entity == null) + { + return NotFound(); + } + country.Patch(entity); + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CountryExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(entity); + } + + private bool CountryExists(string key) + { + var parsedKey = Text.From(key); + return _databaseContext.Countries.Any(p => p.Id == parsedKey); + } + + public async Task Delete([FromRoute] string key) + { + var parsedKey = Text.From(key); + var country = await _databaseContext.Countries.FindAsync(parsedKey); + if (country == null) + { + return NotFound(); + } + + _databaseContext.Countries.Remove(country); + await _databaseContext.SaveChangesAsync(); + return NoContent(); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs new file mode 100644 index 0000000000..6805e60b72 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs @@ -0,0 +1,90 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Domain; + +/// +/// The list of countries. +/// +public partial class Country : AuditableEntityBase +{ + + /// + /// (Optional) + /// + public Text Id { get; set; } = null!; + + /// + /// The country's common name (required). + /// + public Text Name { get; set; } = null!; + + /// + /// The country's official name (required). + /// + public Text FormalName { get; set; } = null!; + + /// + /// The country's official ISO 4217 alpha-3 code (required). + /// + public Text AlphaCode3 { get; set; } = null!; + + /// + /// The country's official ISO 4217 alpha-2 code (required). + /// + public Text AlphaCode2 { get; set; } = null!; + + /// + /// The country's official ISO 4217 alpha-3 code (required). + /// + public Number NumericCode { get; set; } = null!; + + /// + /// The country's phone dialing codes (comma-delimited) (optional). + /// + public Text? DialingCodes { get; set; } = null!; + + /// + /// The capital city of the country (optional). + /// + public Text? Capital { get; set; } = null!; + + /// + /// Noun denoting the natives of the country (optional). + /// + public Text? Demonym { get; set; } = null!; + + /// + /// Country area in square kilometers (required). + /// + public Number AreaInSquareKilometres { get; set; } = null!; + + /// + /// The region the country is in (required). + /// + public Text GeoRegion { get; set; } = null!; + + /// + /// The sub-region the country is in (required). + /// + public Text GeoSubRegion { get; set; } = null!; + + /// + /// The world region the country is in (required). + /// + public Text GeoWorldRegion { get; set; } = null!; + + /// + /// The estimated population of the country (optional). + /// + public Number? Population { get; set; } = null!; + + /// + /// The top level internet domains regitered to the country (comma-delimited) (optional). + /// + public Text? TopLevelDomains { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs new file mode 100644 index 0000000000..fbafdeb1f7 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs @@ -0,0 +1,23 @@ +// Generated + +#nullable enable + +// Generated by DtoGenerator::GenerateDto + +using Nox.Abstractions; +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Application.DataTransferObjects; + +/// +/// Dto for country information. +/// +public partial class CountryDto : IDynamicDto +{ + + /// + /// The identity of the country, the Iso Alpha 2 code. + /// + public Text? Id { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs new file mode 100644 index 0000000000..15779a0736 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs @@ -0,0 +1,26 @@ +// Generated + +#nullable enable + +// Generated by DtoGenerator::GenerateDto + +using Nox.Abstractions; +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Application.DataTransferObjects; + +public partial class CountryInfo : IDynamicDto +{ + + /// + /// The country's Id. + /// + public CountryCode2? CountryId { get; set; } = null!; + + + /// + /// The country name. + /// + public Text? CountryName { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs new file mode 100644 index 0000000000..4a0eb3b9e7 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs @@ -0,0 +1,20 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Domain; + +/// +/// The name of a country in other languages. +/// +public partial class CountryLocalNames : AuditableEntityBase +{ + + /// + /// (Optional) + /// + public Text Id { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs new file mode 100644 index 0000000000..1cd291bdeb --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs @@ -0,0 +1,140 @@ +// Generated + +#nullable enable + +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Deltas; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; +using Microsoft.EntityFrameworkCore; +using SampleWebApp.Domain; +using SampleWebApp.Infrastructure.Persistence; +using Nox.Types; + +namespace SampleWebApp.Presentation.Api.OData; + +public class CountryLocalNamesController : ODataController +{ + SampleWebAppDbContext _databaseContext; + + public CountryLocalNamesController(SampleWebAppDbContext databaseContext) + { + _databaseContext = databaseContext; + } + + [EnableQuery] + public ActionResult> Get() + { + return Ok(_databaseContext.CountryLocalNames); + } + + [EnableQuery] + public ActionResult Get([FromRoute] string key) + { + var parsedKey = Text.From(key); + var item = _databaseContext.CountryLocalNames.SingleOrDefault(d => d.Id.Equals(parsedKey)); + + if (item == null) + { + return NotFound(); + } + return Ok(item); + } + + public async Task Post(CountryLocalNames countrylocalnames) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _databaseContext.CountryLocalNames.Add(countrylocalnames); + + await _databaseContext.SaveChangesAsync(); + + return Created(countrylocalnames); + } + + public async Task Put([FromRoute] string key, [FromBody] CountryLocalNames updatedCountryLocalNames) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + if (parsedKey != updatedCountryLocalNames.Id) + { + return BadRequest(); + } + _databaseContext.Entry(updatedCountryLocalNames).State = EntityState.Modified; + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CountryLocalNamesExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(updatedCountryLocalNames); + } + + public async Task Patch([FromRoute] string key, [FromBody] Delta countrylocalnames) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + var entity = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); + if (entity == null) + { + return NotFound(); + } + countrylocalnames.Patch(entity); + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CountryLocalNamesExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(entity); + } + + private bool CountryLocalNamesExists(string key) + { + var parsedKey = Text.From(key); + return _databaseContext.CountryLocalNames.Any(p => p.Id == parsedKey); + } + + public async Task Delete([FromRoute] string key) + { + var parsedKey = Text.From(key); + var countrylocalnames = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); + if (countrylocalnames == null) + { + return NotFound(); + } + + _databaseContext.CountryLocalNames.Remove(countrylocalnames); + await _databaseContext.SaveChangesAsync(); + return NoContent(); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs new file mode 100644 index 0000000000..30d5eaea89 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs @@ -0,0 +1,28 @@ +// Generated + +#nullable enable + +// Generated by DtoGenerator::GenerateEvent + +using Nox.Abstractions; +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Application.Events; + +/// +/// An application event raised when the name of a country changes. +/// +public partial class CountryNameChangedAppEvent : INoxApplicationEvent +{ + + /// + /// The identifier of the country. The Iso alpha 2 code. + /// + public CountryCode2? CountryId { get; set; } = null!; + + /// + /// The new name of the country. + /// + public Text? CountryName { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs new file mode 100644 index 0000000000..958ab8e47d --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs @@ -0,0 +1,27 @@ +// Generated + +#nullable enable + +// Generated by DomainEventGenerator::GenerateEvent + +using Nox.Abstractions; +using Nox.Types; + +namespace SampleWebApp.Domain; + +/// +/// Raised when the name of a country is changes. +/// +public partial class CountryNameUpdatedEvent : INoxDomainEvent +{ + + /// + /// The identifier of the country. The Iso Alpha2 code of the country. + /// + public CountryCode2? CountryId { get; set; } = null!; + + /// + /// The new name of the country. + /// + public Text? NewCountryName { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs new file mode 100644 index 0000000000..cb8ce6b2a0 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs @@ -0,0 +1,140 @@ +// Generated + +#nullable enable + +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Deltas; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; +using Microsoft.EntityFrameworkCore; +using SampleWebApp.Domain; +using SampleWebApp.Infrastructure.Persistence; +using Nox.Types; + +namespace SampleWebApp.Presentation.Api.OData; + +public class CurrenciesController : ODataController +{ + SampleWebAppDbContext _databaseContext; + + public CurrenciesController(SampleWebAppDbContext databaseContext) + { + _databaseContext = databaseContext; + } + + [EnableQuery] + public ActionResult> Get() + { + return Ok(_databaseContext.Currencies); + } + + [EnableQuery] + public ActionResult Get([FromRoute] string key) + { + var parsedKey = Text.From(key); + var item = _databaseContext.Currencies.SingleOrDefault(d => d.Id.Equals(parsedKey)); + + if (item == null) + { + return NotFound(); + } + return Ok(item); + } + + public async Task Post(Currency currency) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _databaseContext.Currencies.Add(currency); + + await _databaseContext.SaveChangesAsync(); + + return Created(currency); + } + + public async Task Put([FromRoute] string key, [FromBody] Currency updatedCurrency) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + if (parsedKey != updatedCurrency.Id) + { + return BadRequest(); + } + _databaseContext.Entry(updatedCurrency).State = EntityState.Modified; + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CurrencyExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(updatedCurrency); + } + + public async Task Patch([FromRoute] string key, [FromBody] Delta currency) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + var entity = await _databaseContext.Currencies.FindAsync(parsedKey); + if (entity == null) + { + return NotFound(); + } + currency.Patch(entity); + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!CurrencyExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(entity); + } + + private bool CurrencyExists(string key) + { + var parsedKey = Text.From(key); + return _databaseContext.Currencies.Any(p => p.Id == parsedKey); + } + + public async Task Delete([FromRoute] string key) + { + var parsedKey = Text.From(key); + var currency = await _databaseContext.Currencies.FindAsync(parsedKey); + if (currency == null) + { + return NotFound(); + } + + _databaseContext.Currencies.Remove(currency); + await _databaseContext.SaveChangesAsync(); + return NoContent(); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs new file mode 100644 index 0000000000..296af5eefa --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs @@ -0,0 +1,32 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Domain; + +/// +/// The list of currencies. +/// +public partial class Currency : AuditableEntityBase +{ + + /// + /// The currency's primary key / identifier (optional). + /// + public Text Id { get; set; } = null!; + + /// + /// The currency's name (required). + /// + public Text Name { get; set; } = null!; + + /// + /// Currency is legal tender for ZeroOrMany Countries + /// + public List Countries { get; set; } = null!; + + public List CurrencyIsLegalTenderForCountry => Countries; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs new file mode 100644 index 0000000000..61a67ada7e --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs @@ -0,0 +1,18 @@ +// Generated + +#nullable enable + +using System; + +namespace SampleWebApp.Domain; + +/// +/// The base class for all domain entities. +/// +public partial class EntityBase +{ + /// + /// The state of the entity as at this date. + /// + public DateTime AsAt {get; set;} +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs new file mode 100644 index 0000000000..ecfc173c80 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs @@ -0,0 +1,11 @@ +// Generated + +#nullable enable + +// Found files -> +// - currency.entity.nox.yaml +// - elastic.monitoring.nox.yaml +// - sample.solution.nox.yaml +// - store.entity.nox.yaml +// - generator.nox.yaml +// SUCCESS. diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs new file mode 100644 index 0000000000..75759492bb --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs @@ -0,0 +1,32 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; +using System.Threading.Tasks; +using SampleWebApp.Domain; +using SampleWebApp.Application.DataTransferObjects; +using SampleWebApp.Infrastructure.Persistence; + +namespace SampleWebApp.Application; + +/// +/// Returns a list of countries for a given continent. +/// +public abstract partial class GetCountriesByContinentQuery +{ + + /// + /// Represents the DB context. + /// + protected SampleWebAppDbContext DbContext { get; set; } = null!; + + public GetCountriesByContinentQuery( + SampleWebAppDbContext dbContext + ) + { + DbContext = dbContext; + } + public abstract Task> ExecuteAsync(Text continentName); +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs new file mode 100644 index 0000000000..96f9312be0 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs @@ -0,0 +1,27 @@ +// Generated + +#nullable enable + +using Microsoft.EntityFrameworkCore; +using Nox; +using Nox.DatabaseProvider; +using Nox.DatabaseProvider.SqlServer; +using Nox.Types.EntityFramework.SqlServer; +using Nox.Types.EntityFramework.vNext; +using SampleWebApp.Infrastructure.Persistence; + +public static class NoxServiceCollectionExtension +{ + public static IServiceCollection AddNox(this IServiceCollection services) + { + services.AddNoxLib(); + services.AddSingleton>(); + services.AddSingleton(); + services.AddSingleton(); + services.AddDbContext(); + var tmpProvider = services.BuildServiceProvider(); + var dbContext = tmpProvider.GetRequiredService(); + dbContext.Database.EnsureCreated(); + return services; + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs new file mode 100644 index 0000000000..edc2647ca2 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs @@ -0,0 +1,34 @@ +// Generated + +#nullable enable + +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.OData; +using Microsoft.OData.ModelBuilder; +using SampleWebApp.Domain; +namespace SampleWebApp.Presentation.Api.OData; + +public partial class ODataConfiguration +{ + public static void Register(IServiceCollection services) + { + ODataModelBuilder builder = new ODataConventionModelBuilder(); + + builder.EntitySet("Countries"); + builder.EntitySet("Currencies"); + builder.EntitySet("Stores"); + builder.EntitySet("CountryLocalNames"); + + services.AddControllers() + .AddOData(options => options + .Select() + .Filter() + .OrderBy() + .Count() + .Expand() + .SkipToken() + .SetMaxTop(100) + .AddRouteComponents("api", builder.GetEdmModel()) + ); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs new file mode 100644 index 0000000000..2a70b3bf20 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs @@ -0,0 +1,66 @@ +// Generated + +#nullable enable + +using Microsoft.EntityFrameworkCore; +using Nox.DatabaseProvider; +using Nox.Solution; +using Nox.Types.EntityFramework.vNext; +using SampleWebApp.Domain; + +namespace SampleWebApp.Infrastructure.Persistence; + +public partial class SampleWebAppDbContext : DbContext +{ + private readonly NoxSolution _noxSolution; + private readonly INoxDatabaseConfigurator _databaseConfigurator; + private readonly INoxDatabaseProvider _dbProvider; + + public SampleWebAppDbContext( + DbContextOptions options, + NoxSolution noxSolution, + INoxDatabaseConfigurator databaseConfigurator, + INoxDatabaseProvider databaseProvider + ) : base(options) + { + _noxSolution = noxSolution; + _databaseConfigurator = databaseConfigurator; + _dbProvider = databaseProvider; + } + + public DbSet Countries {get; set;} = null!; + + public DbSet Currencies {get; set;} = null!; + + public DbSet Stores {get; set;} = null!; + + public DbSet CountryLocalNames {get; set;} = null!; + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + if (_noxSolution.Infrastructure is { Persistence.DatabaseServer: not null }) + { + _dbProvider.ConfigureDbContext(optionsBuilder, "SampleWebApp", _noxSolution.Infrastructure!.Persistence.DatabaseServer); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + if (_noxSolution.Domain != null) + { + foreach (var entity in _noxSolution.Domain.Entities) + { + var type = Type.GetType("SampleWebApp.Domain." + entity.Name); + + if (type != null) + { + _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); + } + } + + } + } +} + diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs new file mode 100644 index 0000000000..462ee71e47 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs @@ -0,0 +1,30 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Domain; + +/// +/// Stores. +/// +public partial class Store : AuditableEntityBase +{ + + /// + /// Store Primary Key (optional). + /// + public Text Id { get; set; } = null!; + + /// + /// Store Name (required). + /// + public Text Name { get; set; } = null!; + + /// + /// Physical Money in the Physical Store (required). + /// + public Money PhysicalMoney { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs new file mode 100644 index 0000000000..9bbdf7fc66 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs @@ -0,0 +1,140 @@ +// Generated + +#nullable enable + +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Deltas; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Routing.Controllers; +using Microsoft.EntityFrameworkCore; +using SampleWebApp.Domain; +using SampleWebApp.Infrastructure.Persistence; +using Nox.Types; + +namespace SampleWebApp.Presentation.Api.OData; + +public class StoresController : ODataController +{ + SampleWebAppDbContext _databaseContext; + + public StoresController(SampleWebAppDbContext databaseContext) + { + _databaseContext = databaseContext; + } + + [EnableQuery] + public ActionResult> Get() + { + return Ok(_databaseContext.Stores); + } + + [EnableQuery] + public ActionResult Get([FromRoute] string key) + { + var parsedKey = Text.From(key); + var item = _databaseContext.Stores.SingleOrDefault(d => d.Id.Equals(parsedKey)); + + if (item == null) + { + return NotFound(); + } + return Ok(item); + } + + public async Task Post(Store store) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _databaseContext.Stores.Add(store); + + await _databaseContext.SaveChangesAsync(); + + return Created(store); + } + + public async Task Put([FromRoute] string key, [FromBody] Store updatedStore) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + if (parsedKey != updatedStore.Id) + { + return BadRequest(); + } + _databaseContext.Entry(updatedStore).State = EntityState.Modified; + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!StoreExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(updatedStore); + } + + public async Task Patch([FromRoute] string key, [FromBody] Delta store) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + var parsedKey = Text.From(key); + var entity = await _databaseContext.Stores.FindAsync(parsedKey); + if (entity == null) + { + return NotFound(); + } + store.Patch(entity); + try + { + await _databaseContext.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!StoreExists(key)) + { + return NotFound(); + } + else + { + throw; + } + } + return Updated(entity); + } + + private bool StoreExists(string key) + { + var parsedKey = Text.From(key); + return _databaseContext.Stores.Any(p => p.Id == parsedKey); + } + + public async Task Delete([FromRoute] string key) + { + var parsedKey = Text.From(key); + var store = await _databaseContext.Stores.FindAsync(parsedKey); + if (store == null) + { + return NotFound(); + } + + _databaseContext.Stores.Remove(store); + await _databaseContext.SaveChangesAsync(); + return NoContent(); + } +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs new file mode 100644 index 0000000000..9b624fb469 --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs @@ -0,0 +1,20 @@ +// Generated + +#nullable enable + +// Generated by DtoGenerator::GenerateDto + +using Nox.Abstractions; +using Nox.Types; +using System.Collections.Generic; + +namespace SampleWebApp.Application.DataTransferObjects; + + +/// +/// Instructs the service to collect updated population statistics. +/// +public partial class UpdatePopulationStatistics : IDynamicDto +{ + public CountryCode2? CountryCode { get; set; } = null!; +} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs new file mode 100644 index 0000000000..a3cbbae4ea --- /dev/null +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs @@ -0,0 +1,51 @@ +// Generated + +#nullable enable + +using Nox.Types; +using System.Collections.Generic; +using Nox.Abstractions; +using SampleWebApp.Domain; +using SampleWebApp.Application.DataTransferObjects; +using SampleWebApp.Infrastructure.Persistence; + +namespace SampleWebApp.Application; + +/// +/// Instructs the service to collect updated population statistics. +/// +public abstract partial class UpdatePopulationStatisticsCommandHandlerBase +{ + + /// + /// Represents the DB context. + /// + protected SampleWebAppDbContext DbContext { get; set; } = null!; + + /// + /// Represents the Nox messenger. + /// + protected INoxMessenger Messenger { get; set; } = null!; + + public UpdatePopulationStatisticsCommandHandlerBase( + SampleWebAppDbContext dbContext, + INoxMessenger messenger + ) + { + DbContext = dbContext; + Messenger = messenger; + } + + /// + /// Executes UpdatePopulationStatistics. + /// + public abstract Task ExecuteAsync(UpdatePopulationStatistics command); + + /// + /// Sends CountryNameUpdatedEvent. + /// + public async Task SendCountryNameUpdatedEventDomainEventAsync(CountryNameUpdatedEvent domainEvent) + { + await Messenger.SendMessageAsync(new string[] { "Mediator" }, domainEvent); + } +} From 6906e922cd0a287c7b240167e580d4981bcfece4 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 09:29:49 +0200 Subject: [PATCH 08/18] fixed generator tests --- tests/Nox.Generator.Tests/Application/ApplicationEventTests.cs | 3 ++- .../Application/DataTransferObjectsTests.cs | 3 ++- tests/Nox.Generator.Tests/Domain/CommandTests.cs | 3 ++- tests/Nox.Generator.Tests/Domain/DomainEventTests.cs | 3 ++- tests/Nox.Generator.Tests/Domain/QueryTests.cs | 3 ++- .../Infrastructure/Persistence/DatabaseServerTests.cs | 1 + tests/Nox.Generator.Tests/Presentation/ApiControllerTest.cs | 3 ++- 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/Nox.Generator.Tests/Application/ApplicationEventTests.cs b/tests/Nox.Generator.Tests/Application/ApplicationEventTests.cs index d1aca35491..066bff947f 100644 --- a/tests/Nox.Generator.Tests/Application/ApplicationEventTests.cs +++ b/tests/Nox.Generator.Tests/Application/ApplicationEventTests.cs @@ -43,7 +43,8 @@ public void Can_generate_a_domain_event_file() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(2, generatedSources.Length); + Assert.Equal(3, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator not generated"); Assert.True(generatedSources.Any(s => s.HintName == "CountryNameChangedAppEvent.g.cs"), "CountryNameChangedAppEvent not generated"); //can further extend this test to verify contents of source files. diff --git a/tests/Nox.Generator.Tests/Application/DataTransferObjectsTests.cs b/tests/Nox.Generator.Tests/Application/DataTransferObjectsTests.cs index 0226b03a96..eafcead636 100644 --- a/tests/Nox.Generator.Tests/Application/DataTransferObjectsTests.cs +++ b/tests/Nox.Generator.Tests/Application/DataTransferObjectsTests.cs @@ -43,7 +43,8 @@ public void Can_generate_a_dto_file() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(2, generatedSources.Length); + Assert.Equal(3, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator not generated"); Assert.True(generatedSources.Any(s => s.HintName == "CountryDto.g.cs"), "CountryDto not generated"); //can further extend this test to verify contents of source files. diff --git a/tests/Nox.Generator.Tests/Domain/CommandTests.cs b/tests/Nox.Generator.Tests/Domain/CommandTests.cs index eac1d48430..776f073680 100644 --- a/tests/Nox.Generator.Tests/Domain/CommandTests.cs +++ b/tests/Nox.Generator.Tests/Domain/CommandTests.cs @@ -42,7 +42,8 @@ public void Can_generate_domain_command_files() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(6, generatedSources.Length); + Assert.Equal(7, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "EntityBase.g.cs"), "EntityBase.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "AuditableEntityBase.g.cs"), "AuditableEntityBase.g.cs not generated"); diff --git a/tests/Nox.Generator.Tests/Domain/DomainEventTests.cs b/tests/Nox.Generator.Tests/Domain/DomainEventTests.cs index 2a1c33adab..877bc77f5a 100644 --- a/tests/Nox.Generator.Tests/Domain/DomainEventTests.cs +++ b/tests/Nox.Generator.Tests/Domain/DomainEventTests.cs @@ -41,7 +41,8 @@ public void Can_generate_domain_event_files() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(5, generatedSources.Length); + Assert.Equal(6, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "EntityBase.g.cs"), "EntityBase.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "AuditableEntityBase.g.cs"), "AuditableEntityBase.g.cs not generated"); diff --git a/tests/Nox.Generator.Tests/Domain/QueryTests.cs b/tests/Nox.Generator.Tests/Domain/QueryTests.cs index e467cd688e..639d9355fe 100644 --- a/tests/Nox.Generator.Tests/Domain/QueryTests.cs +++ b/tests/Nox.Generator.Tests/Domain/QueryTests.cs @@ -43,7 +43,8 @@ public void Can_generate_domain_query_files() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(6, generatedSources.Length); + Assert.Equal(7, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "EntityBase.g.cs"), "EntityBase.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "AuditableEntityBase.g.cs"), "AuditableEntityBase.g.cs not generated"); diff --git a/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs b/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs index a127cd6a0a..a28000bf5a 100644 --- a/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs +++ b/tests/Nox.Generator.Tests/Infrastructure/Persistence/DatabaseServerTests.cs @@ -43,6 +43,7 @@ public void Can_generate_database_server_files() var generatedSources = result.GeneratedSources; Assert.Equal(6, generatedSources.Length); Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "EntityBase.g.cs"), "EntityBase.g.cs not generated"); Assert.True(generatedSources.Any(s => s.HintName == "AuditableEntityBase.g.cs"), "AuditableEntityBase.g.cs not generated"); diff --git a/tests/Nox.Generator.Tests/Presentation/ApiControllerTest.cs b/tests/Nox.Generator.Tests/Presentation/ApiControllerTest.cs index d6e11c9091..7b1d02e1f4 100644 --- a/tests/Nox.Generator.Tests/Presentation/ApiControllerTest.cs +++ b/tests/Nox.Generator.Tests/Presentation/ApiControllerTest.cs @@ -42,7 +42,8 @@ public void Can_generate_domain_api_controller_files() Assert.Single(allOutputs); var generatedSources = result.GeneratedSources; - Assert.Equal(11, generatedSources.Length); + Assert.Equal(12, generatedSources.Length); + Assert.True(generatedSources.Any(s => s.HintName == "NoxServiceCollectionExtension.g.cs"), "NoxServiceCollectionExtension.g.cs not generated"); // Check base files Assert.True(generatedSources.Any(s => s.HintName == "Generator.g.cs"), "Generator.g.cs not generated"); From 2e960b7aa9c86c98c7bd1615dcbbd13fbddea275 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 09:54:19 +0200 Subject: [PATCH 09/18] added postgres to docker --- docker-compose.postgres.yml | 19 +++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ .../Nox.DatabaseProvider.Postgres.csproj | 9 +++++++++ .../PostgresDatabaseProvider.cs | 6 ++++++ 4 files changed, 49 insertions(+) create mode 100644 docker-compose.postgres.yml create mode 100644 src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj create mode 100644 src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs diff --git a/docker-compose.postgres.yml b/docker-compose.postgres.yml new file mode 100644 index 0000000000..2c0a3f4e14 --- /dev/null +++ b/docker-compose.postgres.yml @@ -0,0 +1,19 @@ +version: '3.7' + +volumes: + postgres: + +services: + postgres: + container_name: postgres_container + image: postgres:14-alpine + restart: always + environment: + POSTGRES_DB: SampleCurrencyDb + POSTGRES_USER: "sa" + POSTGRES_PASSWORD: "Developer*123" + PGDATA: ./data + ports: + - "54320:5432" + volumes: + - postgres:/var/lib/postgresql/data \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 530e8ed08f..0ec817322f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ version: '3.7' volumes: sqlserver: + postgres: esdata: driver: local @@ -19,6 +20,20 @@ services: volumes: - sqlserver:/var/opt/mssql/data + postgres: + container_name: postgres_container + image: postgres:14-alpine + restart: always + environment: + POSTGRES_DB: SampleCurrencyDb + POSTGRES_USER: "sa" + POSTGRES_PASSWORD: "Developer*123" + PGDATA: ./data + ports: + - "54320:5432" + volumes: + - postgres:/var/lib/postgresql/data + apm-server: container_name: apm-server image: docker.elastic.co/apm/apm-server:7.17.10 diff --git a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj new file mode 100644 index 0000000000..6836c6808f --- /dev/null +++ b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs new file mode 100644 index 0000000000..06ed1213e3 --- /dev/null +++ b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs @@ -0,0 +1,6 @@ +namespace Nox.DatabaseProvider.Postgres; + +public class PostgresDatabaseProvider +{ + +} \ No newline at end of file From a4b9ead4de5c3dd078838135fb509d7f1ba39634 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 09:56:04 +0200 Subject: [PATCH 10/18] - added postgres database provider --- .../Nox.DatabaseProvider.Postgres.csproj | 8 ++++ .../PostgresDatabaseProvider.cs | 46 ++++++++++++++++++- .../SqlServerDatabaseProvider.cs | 2 +- src/Nox.Generator.sln | 7 +++ src/Nox.Lib/Nox.Lib.csproj | 1 + 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj index 6836c6808f..7f1546f7c2 100644 --- a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj +++ b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj @@ -6,4 +6,12 @@ enable + + + + + + + + diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs index 06ed1213e3..03119d1ac3 100644 --- a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs @@ -1,6 +1,50 @@ +using Microsoft.EntityFrameworkCore; +using Nox.Solution; +using Npgsql; + namespace Nox.DatabaseProvider.Postgres; public class PostgresDatabaseProvider { - + private string _connectionString = string.Empty; + + public string ConnectionString + { + get => _connectionString; + set => SetConnectionString(value); + } + + public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer) + { + var csb = new NpgsqlConnectionStringBuilder(dbServer.Options) + { + Host = dbServer.ServerUri, + Port = dbServer.Port ?? 5432, + Username = dbServer.User, + Password = dbServer.User, + Database = dbServer.Name, + ApplicationName = applicationName + }; + SetConnectionString(csb.ConnectionString); + + return optionsBuilder.UseNpgsql(_connectionString, opts => + { + opts.MigrationsHistoryTable("MigrationsHistory", "migrations"); + }); + } + + public string ToTableNameForSql(string table, string schema) + { + throw new NotImplementedException(); + } + + public string ToTableNameForSqlRaw(string table, string schema) + { + throw new NotImplementedException(); + } + + private void SetConnectionString(string connectionString) + { + _connectionString = connectionString; + } } \ No newline at end of file diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs index 27cdcc3fb5..333f5b2bd6 100644 --- a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs @@ -18,7 +18,7 @@ public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder option { var csb = new SqlConnectionStringBuilder(dbServer.Options) { - DataSource = $"{dbServer.ServerUri},{dbServer.Port}", + DataSource = $"{dbServer.ServerUri},{dbServer.Port ?? 1433}", UserID = dbServer.User, Password = dbServer.Password, InitialCatalog = dbServer.Name, diff --git a/src/Nox.Generator.sln b/src/Nox.Generator.sln index fa85411502..84a442cf36 100644 --- a/src/Nox.Generator.sln +++ b/src/Nox.Generator.sln @@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider", "Nox EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.SqlServer", "Nox.DatabaseProvider.SqlServer\Nox.DatabaseProvider.SqlServer.csproj", "{7435EFBA-471C-4BFB-A306-EB9CDF375585}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Postgres", "Nox.DatabaseProvider.Postgres\Nox.DatabaseProvider.Postgres.csproj", "{3AED54D4-4674-46E0-9289-099019E82A70}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -153,6 +155,10 @@ Global {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Debug|Any CPU.Build.0 = Debug|Any CPU {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.ActiveCfg = Release|Any CPU {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.Build.0 = Release|Any CPU + {3AED54D4-4674-46E0-9289-099019E82A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3AED54D4-4674-46E0-9289-099019E82A70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3AED54D4-4674-46E0-9289-099019E82A70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3AED54D4-4674-46E0-9289-099019E82A70}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -176,6 +182,7 @@ Global {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} {1D6D928A-AA0F-40F6-8930-47B695919104} = {137019F4-2B62-4DD8-B2F8-0F5067205101} {7435EFBA-471C-4BFB-A306-EB9CDF375585} = {137019F4-2B62-4DD8-B2F8-0F5067205101} + {3AED54D4-4674-46E0-9289-099019E82A70} = {137019F4-2B62-4DD8-B2F8-0F5067205101} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0E72B357-9E1E-43B5-9868-8D2B74CB2AF0} diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index bf161e439a..8b7030d034 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,6 +36,7 @@ + From 7abc27a1dbb3b2397b2607edd2d33d3b3b0c913e Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 11:50:22 +0200 Subject: [PATCH 11/18] - fixed PostgresDatabaseConfigurator.cs - fixed PostgresDatabaseProvider.cs --- .nox/design/sample.solution.nox.yaml | 20 +++++++----- .../PostgresDatabaseProvider.cs | 6 ++-- .../ServiceCollectionExtensionGenerator.cs | 32 ++++++++++++++++--- src/Nox.Lib/Nox.Lib.csproj | 1 + .../PostgresDatabaseConfigurator.cs | 4 +-- ...Nox.Types.EntityFramework.SqlServer.csproj | 8 ++--- .../NoxServiceCollectionExtension.g.cs | 8 ++--- src/SampleWebApp/SampleWebApp.csproj | 4 +++ 8 files changed, 58 insertions(+), 25 deletions(-) diff --git a/.nox/design/sample.solution.nox.yaml b/.nox/design/sample.solution.nox.yaml index 6a5a1a6932..cbbdb669b4 100644 --- a/.nox/design/sample.solution.nox.yaml +++ b/.nox/design/sample.solution.nox.yaml @@ -412,16 +412,20 @@ infrastructure: name: SampleCurrencyDb # Sql Server + #serverUri: localhost + #provider: sqlServer + #port: 1433 + #user: sa + #password: Developer*123 + #options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; + + # Postgres serverUri: localhost - provider: sqlServer - port: 1433 + provider: postgres + port: 54320 user: sa - password: Developer*123 - options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; - - ### Postgres - #provider: postgres - + password: Developer*123 + ### MySql #provider: mySql diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs index 03119d1ac3..55adab07f8 100644 --- a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs @@ -4,7 +4,7 @@ namespace Nox.DatabaseProvider.Postgres; -public class PostgresDatabaseProvider +public class PostgresDatabaseProvider: INoxDatabaseProvider { private string _connectionString = string.Empty; @@ -21,9 +21,9 @@ public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder option Host = dbServer.ServerUri, Port = dbServer.Port ?? 5432, Username = dbServer.User, - Password = dbServer.User, + Password = dbServer.Password, Database = dbServer.Name, - ApplicationName = applicationName + ApplicationName = applicationName, }; SetConnectionString(csb.ConnectionString); diff --git a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs index 7232316249..b2272acfb3 100644 --- a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs +++ b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Microsoft.CodeAnalysis; using Nox.Solution; @@ -10,12 +11,35 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio context.CancellationToken.ThrowIfCancellationRequested(); var code = new CodeBuilder($"NoxServiceCollectionExtension.g.cs", context); + + var usings = new List(); + var dbConfigurator = ""; + var dbProvider = ""; + + if (solution.Infrastructure?.Persistence is { DatabaseServer: not null }) + { + var dbServer = solution.Infrastructure.Persistence.DatabaseServer; + switch (dbServer.Provider) + { + case DatabaseServerProvider.SqlServer: + usings.Add("using Nox.DatabaseProvider.SqlServer;"); + usings.Add("using Nox.Types.EntityFramework.SqlServer;"); + dbConfigurator = "SqlServerDatabaseConfigurator"; + dbProvider = "SqlServerDatabaseProvider"; + break; + case DatabaseServerProvider.Postgres: + usings.Add("using Nox.DatabaseProvider.Postgres;"); + usings.Add("using Nox.Types.EntityFramework.Postgres;"); + dbConfigurator = "PostgresDatabaseConfigurator"; + dbProvider = "PostgresDatabaseProvider"; + break; + } + } code.AppendLine("using Microsoft.EntityFrameworkCore;"); code.AppendLine("using Nox;"); code.AppendLine("using Nox.DatabaseProvider;"); - code.AppendLine("using Nox.DatabaseProvider.SqlServer;"); - code.AppendLine("using Nox.Types.EntityFramework.SqlServer;"); + code.AppendLines(usings.ToArray()); code.AppendLine("using Nox.Types.EntityFramework.vNext;"); code.AppendLine("using SampleWebApp.Infrastructure.Persistence;"); code.AppendLine(); @@ -29,8 +53,8 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio { var dbContextName = $"{solution.Name}DbContext"; code.AppendLine($"services.AddSingleton>();"); - code.AppendLine("services.AddSingleton();"); - code.AppendLine("services.AddSingleton();"); + code.AppendLine($"services.AddSingleton();"); + code.AppendLine($"services.AddSingleton();"); code.AppendLine($"services.AddDbContext<{dbContextName}>();"); code.AppendLine("var tmpProvider = services.BuildServiceProvider();"); code.AppendLine($"var dbContext = tmpProvider.GetRequiredService<{dbContextName}>();"); diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index 8b7030d034..bafbe1c097 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -44,6 +44,7 @@ + diff --git a/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs index 578e50ddc3..a19adf6808 100644 --- a/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs @@ -3,7 +3,7 @@ namespace Nox.Types.EntityFramework.Postgres; -public class PostgresDatabaseConfigurator: NoxDatabaseConfigurator +public sealed class PostgresDatabaseConfigurator: NoxDatabaseConfigurator { private static readonly Dictionary TypesConfiguration = new() @@ -13,7 +13,7 @@ public class PostgresDatabaseConfigurator: NoxDatabaseConfigurator { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation }; - public PostgresDatabaseConfigurator(Dictionary typesConfiguration) : base(TypesConfiguration) + public PostgresDatabaseConfigurator() : base(TypesConfiguration) { } } \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj b/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj index 4f6ffab88b..9facf826ec 100644 --- a/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj +++ b/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj @@ -14,10 +14,10 @@ True - - - - + + + + diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs index 96f9312be0..2734cb8cea 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs @@ -5,8 +5,8 @@ using Microsoft.EntityFrameworkCore; using Nox; using Nox.DatabaseProvider; -using Nox.DatabaseProvider.SqlServer; -using Nox.Types.EntityFramework.SqlServer; +using Nox.DatabaseProvider.Postgres; +using Nox.Types.EntityFramework.Postgres; using Nox.Types.EntityFramework.vNext; using SampleWebApp.Infrastructure.Persistence; @@ -16,8 +16,8 @@ public static IServiceCollection AddNox(this IServiceCollection services) { services.AddNoxLib(); services.AddSingleton>(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddDbContext(); var tmpProvider = services.BuildServiceProvider(); var dbContext = tmpProvider.GetRequiredService(); diff --git a/src/SampleWebApp/SampleWebApp.csproj b/src/SampleWebApp/SampleWebApp.csproj index 774acbce18..db5d7991b7 100644 --- a/src/SampleWebApp/SampleWebApp.csproj +++ b/src/SampleWebApp/SampleWebApp.csproj @@ -55,4 +55,8 @@ + + + + \ No newline at end of file From af99a25612cf835bb6e2225073a86a7aa07b046e Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 13:37:35 +0200 Subject: [PATCH 12/18] - reorganize database configurators and providers --- .nox/design/sample.solution.nox.yaml | 22 +++--- .../Persistence/INoxDatabaseProvider.cs | 9 --- .../Nox.DatabaseProvider.Postgres.csproj | 4 +- .../PostgresDatabaseProvider.cs | 18 ++++- .../PostgresTextDatabaseConfiguration.cs | 5 +- .../Nox.DatabaseProvider.SqlServer.csproj | 2 +- .../SqlServerDatabaseProvider.cs | 19 ++++- .../SqlServerTextDatabaseConfigurator.cs | 5 +- .../Nox.DatabaseProvider.Sqlite.csproj | 13 ++++ .../SqliteDatabaseConfigurator.cs | 9 +-- .../Nox.DatabaseProvider.csproj | 19 ----- src/Nox.Generator.sln | 70 ++++++------------- .../ServiceCollectionExtensionGenerator.cs | 3 - .../DbContextGenerator/DbContextGenerator.cs | 3 +- .../Extensions/ServiceCollectionExtension.cs | 1 - src/Nox.Lib/Nox.Lib.csproj | 5 -- .../Nox.Types.EntityFramework.Postgres.csproj | 2 +- .../PostgresDatabaseConfigurator.cs | 19 ----- ...Nox.Types.EntityFramework.SqlServer.csproj | 2 +- .../SqlServerDatabaseConfigurator.cs | 20 ------ .../Nox.Types.EntityFramework.Sqlite.csproj | 4 -- .../NoxDatabaseProviderException.cs | 2 +- .../NoxEntityFrameworkException.cs | 2 +- .../INoxDatabaseConfigurator.cs | 11 --- .../Nox.Types.EntityFramework.vNext.csproj | 4 ++ .../Abstractions/INoxDatabaseConfigurator.cs | 9 +++ .../Abstractions}/INoxDatabaseProvider.cs | 2 +- .../INoxTypeDatabaseConfigurator.cs | 2 +- .../MoneyDatabaseConfigurator.cs | 3 +- .../Configurators}/NoxDatabaseConfigurator.cs | 4 +- .../NumberDatabaseConfigurator.cs | 3 +- .../TextDatabaseConfigurator.cs | 3 +- .../FluentApiUtil.cs | 2 +- .../Nox.Types.EntityFramework.csproj | 4 +- .../NoxServiceCollectionExtension.g.cs | 8 +-- src/SampleWebApp/SampleWebApp.csproj | 2 - 36 files changed, 128 insertions(+), 187 deletions(-) delete mode 100644 src/Nox.Abstractions/Infrastructure/Persistence/INoxDatabaseProvider.cs rename src/{Nox.Types.EntityFramework.Postgres => Nox.DatabaseProvider.Postgres}/PostgresTextDatabaseConfiguration.cs (73%) rename src/{Nox.Types.EntityFramework.SqlServer => Nox.DatabaseProvider.SqlServer}/SqlServerTextDatabaseConfigurator.cs (66%) create mode 100644 src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj rename src/{Nox.Types.EntityFramework.Sqlite => Nox.DatabaseProvider.Sqlite}/SqliteDatabaseConfigurator.cs (75%) delete mode 100644 src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj delete mode 100644 src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs delete mode 100644 src/Nox.Types.EntityFramework.SqlServer/SqlServerDatabaseConfigurator.cs rename src/{Nox.DatabaseProvider => Nox.Types.EntityFramework.vNext/Exceptions}/NoxDatabaseProviderException.cs (86%) rename src/Nox.Types.EntityFramework.vNext/{ => Exceptions}/NoxEntityFrameworkException.cs (87%) delete mode 100644 src/Nox.Types.EntityFramework.vNext/INoxDatabaseConfigurator.cs create mode 100644 src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseConfigurator.cs rename src/{Nox.DatabaseProvider => Nox.Types.EntityFramework/Abstractions}/INoxDatabaseProvider.cs (89%) rename src/{Nox.Types.EntityFramework.vNext/Types => Nox.Types.EntityFramework/Abstractions}/INoxTypeDatabaseConfigurator.cs (82%) rename src/{Nox.Types.EntityFramework.vNext/Types => Nox.Types.EntityFramework/Configurators}/MoneyDatabaseConfigurator.cs (86%) rename src/{Nox.Types.EntityFramework.vNext => Nox.Types.EntityFramework/Configurators}/NoxDatabaseConfigurator.cs (95%) rename src/{Nox.Types.EntityFramework.vNext/Types => Nox.Types.EntityFramework/Configurators}/NumberDatabaseConfigurator.cs (95%) rename src/{Nox.Types.EntityFramework.vNext/Types => Nox.Types.EntityFramework/Configurators}/TextDatabaseConfigurator.cs (91%) rename src/{Nox.Types.EntityFramework.vNext => Nox.Types.EntityFramework}/FluentApiUtil.cs (90%) diff --git a/.nox/design/sample.solution.nox.yaml b/.nox/design/sample.solution.nox.yaml index cbbdb669b4..ccaf533767 100644 --- a/.nox/design/sample.solution.nox.yaml +++ b/.nox/design/sample.solution.nox.yaml @@ -412,19 +412,19 @@ infrastructure: name: SampleCurrencyDb # Sql Server - #serverUri: localhost - #provider: sqlServer - #port: 1433 - #user: sa - #password: Developer*123 - #options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; - - # Postgres serverUri: localhost - provider: postgres - port: 54320 + provider: sqlServer + port: 1433 user: sa - password: Developer*123 + password: Developer*123 + options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True; + + # Postgres + #serverUri: localhost + #provider: postgres + #port: 54320 + #user: sa + #password: Developer*123 ### MySql #provider: mySql diff --git a/src/Nox.Abstractions/Infrastructure/Persistence/INoxDatabaseProvider.cs b/src/Nox.Abstractions/Infrastructure/Persistence/INoxDatabaseProvider.cs deleted file mode 100644 index 4ed5819f2f..0000000000 --- a/src/Nox.Abstractions/Infrastructure/Persistence/INoxDatabaseProvider.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Nox.Types; - -namespace Nox.Abstractions.Infrastructure.Persistence -{ - public interface INoxDatabaseProvider - { - string ToDatabaseColumnType(TO options) where T : INoxType where TO : class; //TODO TO INoxOptions? - } -} \ No newline at end of file diff --git a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj index 7f1546f7c2..d9fa899d2a 100644 --- a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj +++ b/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj @@ -7,11 +7,11 @@ - + - + diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs index 55adab07f8..3a9a8be7d7 100644 --- a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs @@ -1,12 +1,28 @@ using Microsoft.EntityFrameworkCore; using Nox.Solution; +using Nox.Types; +using Nox.Types.EntityFramework.Abstractions; +using Nox.Types.EntityFramework.Configurators; using Npgsql; namespace Nox.DatabaseProvider.Postgres; -public class PostgresDatabaseProvider: INoxDatabaseProvider +public class PostgresDatabaseProvider: NoxDatabaseConfigurator, INoxDatabaseProvider { private string _connectionString = string.Empty; + + private static readonly Dictionary TypesConfiguration = + new() + { + { NoxType.Text, new PostgresTextDatabaseConfiguration() }, //Use Postgres Implementation + { NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation + { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation + }; + + public PostgresDatabaseProvider(): base(TypesConfiguration) + { + + } public string ConnectionString { diff --git a/src/Nox.Types.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs b/src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs similarity index 73% rename from src/Nox.Types.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs rename to src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs index 933b16f082..682c5cacde 100644 --- a/src/Nox.Types.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs +++ b/src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs @@ -1,6 +1,7 @@ -using Nox.Types.EntityFramework.vNext.Types; +using Nox.Types; +using Nox.Types.EntityFramework.Configurators; -namespace Nox.Types.EntityFramework.Postgres; +namespace Nox.DatabaseProvider.Postgres; public class PostgresTextDatabaseConfiguration : TextDatabaseConfigurator { diff --git a/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj b/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj index cdcadcbcfa..9ee968485f 100644 --- a/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj +++ b/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs index 333f5b2bd6..7e7e1af48f 100644 --- a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs @@ -1,11 +1,23 @@ using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Nox.Solution; +using Nox.Types; +using Nox.Types.EntityFramework.Abstractions; +using Nox.Types.EntityFramework.Configurators; namespace Nox.DatabaseProvider.SqlServer; -public class SqlServerDatabaseProvider: INoxDatabaseProvider +public class SqlServerDatabaseProvider: NoxDatabaseConfigurator, INoxDatabaseProvider { + //We could use the container to manage this + private static readonly Dictionary TypesConfiguration = + new() + { + { NoxType.Text, new SqlServerTextDatabaseConfigurator() }, //Use MySql Implementation + { NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation + { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation + }; + private string _connectionString = string.Empty; public string ConnectionString @@ -13,6 +25,11 @@ public string ConnectionString get => _connectionString; set => SetConnectionString(value); } + + public SqlServerDatabaseProvider(): base(TypesConfiguration) + { + + } public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer) { diff --git a/src/Nox.Types.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs b/src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs similarity index 66% rename from src/Nox.Types.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs rename to src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs index 34a59ff647..7280a47761 100644 --- a/src/Nox.Types.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs +++ b/src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs @@ -1,6 +1,7 @@ -using Nox.Types.EntityFramework.vNext.Types; +using Nox.Types; +using Nox.Types.EntityFramework.Configurators; -namespace Nox.Types.EntityFramework.SqlServer; +namespace Nox.DatabaseProvider.SqlServer; public class SqlServerTextDatabaseConfigurator : TextDatabaseConfigurator { diff --git a/src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj b/src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj new file mode 100644 index 0000000000..67bc262c1c --- /dev/null +++ b/src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/src/Nox.Types.EntityFramework.Sqlite/SqliteDatabaseConfigurator.cs b/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs similarity index 75% rename from src/Nox.Types.EntityFramework.Sqlite/SqliteDatabaseConfigurator.cs rename to src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs index 9c40cd6440..7f2eb7ddcd 100644 --- a/src/Nox.Types.EntityFramework.Sqlite/SqliteDatabaseConfigurator.cs +++ b/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs @@ -1,9 +1,10 @@ -using Nox.Types.EntityFramework.vNext; -using Nox.Types.EntityFramework.vNext.Types; +using Nox.Types; +using Nox.Types.EntityFramework.Abstractions; +using Nox.Types.EntityFramework.Configurators; -namespace Nox.Types.EntityFramework.Sqlite; +namespace Nox.DatabaseProvider.Sqlite; -public sealed class SqliteDatabaseConfigurator : NoxDatabaseConfigurator +public sealed class SqliteDatabaseConfigurator : NoxDatabaseConfigurator { private static readonly Dictionary _typesConfiguration = new() { diff --git a/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj b/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj deleted file mode 100644 index 5d240523b5..0000000000 --- a/src/Nox.DatabaseProvider/Nox.DatabaseProvider.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net7.0 - enable - enable - - - - - - - - - - - - - diff --git a/src/Nox.Generator.sln b/src/Nox.Generator.sln index 84a442cf36..be8de462d3 100644 --- a/src/Nox.Generator.sln +++ b/src/Nox.Generator.sln @@ -15,22 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Abstractions", "Nox.Abs EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Monitoring", "Nox.Monitoring\Nox.Monitoring.csproj", "{E054D012-2AA7-4B70-9CDC-253FF510B0C8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Types.EntityFramework.Sqlite", "Nox.Types.EntityFramework.Sqlite\Nox.Types.EntityFramework.Sqlite.csproj", "{18BFFAE7-E697-4BA8-91D8-DA725F5C8188}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DatabaseConfigurators", "DatabaseConfigurators", "{631CE917-1F5D-42D9-81A4-575C13B84826}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Types.EntityFramework.SqlServer", "Nox.Types.EntityFramework.SqlServer\Nox.Types.EntityFramework.SqlServer.csproj", "{F59896AE-4A84-4AA8-BB45-7BFED102D14E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Types.EntityFramework.vNext", "Nox.Types.EntityFramework.vNext\Nox.Types.EntityFramework.vNext.csproj", "{994036C2-1EFA-46AF-8531-F0C5D4DB22C1}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Logging", "Nox.Logging\Nox.Logging.csproj", "{DBA5FE1B-100F-460F-B192-320B5C85949C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Logging.Serilog", "Nox.Logging.Serilog\Nox.Logging.Serilog.csproj", "{7BD651E7-3B5C-4118-963C-629C34F30258}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Types.EntityFramework.Tests", "..\tests\Nox.Types.EntityFramework.Tests\Nox.Types.EntityFramework.Tests.csproj", "{9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nox.Types.EntityFramework.Postgres", "Nox.Types.EntityFramework.Postgres\Nox.Types.EntityFramework.Postgres.csproj", "{8AA4B104-864A-4188-A1AE-481E71D4D533}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Types", "Types", "{110C16ED-A11D-4B5A-ABB2-0E0F4692C77A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{4A930AE8-3A32-48A4-BCDB-0F55FA53AE4B}" @@ -57,13 +47,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.Types.EntityFramework", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.Types.Tests", "..\tests\Nox.Types.Tests\Nox.Types.Tests.csproj", "{A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DatabaseProviders", "DatabaseProviders", "{137019F4-2B62-4DD8-B2F8-0F5067205101}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DatabaseProviders", "DatabaseProviders", "{873BFCC4-435D-44D7-8287-1FB1574B2319}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider", "Nox.DatabaseProvider\Nox.DatabaseProvider.csproj", "{1D6D928A-AA0F-40F6-8930-47B695919104}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Postgres", "Nox.DatabaseProvider.Postgres\Nox.DatabaseProvider.Postgres.csproj", "{55D717E8-6043-487C-83A9-8AE2E92086D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.SqlServer", "Nox.DatabaseProvider.SqlServer\Nox.DatabaseProvider.SqlServer.csproj", "{7435EFBA-471C-4BFB-A306-EB9CDF375585}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.SqlServer", "Nox.DatabaseProvider.SqlServer\Nox.DatabaseProvider.SqlServer.csproj", "{A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Postgres", "Nox.DatabaseProvider.Postgres\Nox.DatabaseProvider.Postgres.csproj", "{3AED54D4-4674-46E0-9289-099019E82A70}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Sqlite", "Nox.DatabaseProvider.Sqlite\Nox.DatabaseProvider.Sqlite.csproj", "{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -95,18 +85,6 @@ Global {E054D012-2AA7-4B70-9CDC-253FF510B0C8}.Debug|Any CPU.Build.0 = Debug|Any CPU {E054D012-2AA7-4B70-9CDC-253FF510B0C8}.Release|Any CPU.ActiveCfg = Release|Any CPU {E054D012-2AA7-4B70-9CDC-253FF510B0C8}.Release|Any CPU.Build.0 = Release|Any CPU - {18BFFAE7-E697-4BA8-91D8-DA725F5C8188}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {18BFFAE7-E697-4BA8-91D8-DA725F5C8188}.Debug|Any CPU.Build.0 = Debug|Any CPU - {18BFFAE7-E697-4BA8-91D8-DA725F5C8188}.Release|Any CPU.ActiveCfg = Release|Any CPU - {18BFFAE7-E697-4BA8-91D8-DA725F5C8188}.Release|Any CPU.Build.0 = Release|Any CPU - {F59896AE-4A84-4AA8-BB45-7BFED102D14E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F59896AE-4A84-4AA8-BB45-7BFED102D14E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F59896AE-4A84-4AA8-BB45-7BFED102D14E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F59896AE-4A84-4AA8-BB45-7BFED102D14E}.Release|Any CPU.Build.0 = Release|Any CPU - {994036C2-1EFA-46AF-8531-F0C5D4DB22C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {994036C2-1EFA-46AF-8531-F0C5D4DB22C1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {994036C2-1EFA-46AF-8531-F0C5D4DB22C1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {994036C2-1EFA-46AF-8531-F0C5D4DB22C1}.Release|Any CPU.Build.0 = Release|Any CPU {DBA5FE1B-100F-460F-B192-320B5C85949C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DBA5FE1B-100F-460F-B192-320B5C85949C}.Debug|Any CPU.Build.0 = Debug|Any CPU {DBA5FE1B-100F-460F-B192-320B5C85949C}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -119,10 +97,6 @@ Global {9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1}.Debug|Any CPU.Build.0 = Debug|Any CPU {9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1}.Release|Any CPU.ActiveCfg = Release|Any CPU {9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1}.Release|Any CPU.Build.0 = Release|Any CPU - {8AA4B104-864A-4188-A1AE-481E71D4D533}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8AA4B104-864A-4188-A1AE-481E71D4D533}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8AA4B104-864A-4188-A1AE-481E71D4D533}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8AA4B104-864A-4188-A1AE-481E71D4D533}.Release|Any CPU.Build.0 = Release|Any CPU {58599385-98BD-44A4-9990-A7AEDCAFC8A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {58599385-98BD-44A4-9990-A7AEDCAFC8A0}.Debug|Any CPU.Build.0 = Debug|Any CPU {58599385-98BD-44A4-9990-A7AEDCAFC8A0}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -147,18 +121,18 @@ Global {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4}.Release|Any CPU.Build.0 = Release|Any CPU - {1D6D928A-AA0F-40F6-8930-47B695919104}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1D6D928A-AA0F-40F6-8930-47B695919104}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1D6D928A-AA0F-40F6-8930-47B695919104}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1D6D928A-AA0F-40F6-8930-47B695919104}.Release|Any CPU.Build.0 = Release|Any CPU - {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7435EFBA-471C-4BFB-A306-EB9CDF375585}.Release|Any CPU.Build.0 = Release|Any CPU - {3AED54D4-4674-46E0-9289-099019E82A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3AED54D4-4674-46E0-9289-099019E82A70}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3AED54D4-4674-46E0-9289-099019E82A70}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3AED54D4-4674-46E0-9289-099019E82A70}.Release|Any CPU.Build.0 = Release|Any CPU + {55D717E8-6043-487C-83A9-8AE2E92086D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55D717E8-6043-487C-83A9-8AE2E92086D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55D717E8-6043-487C-83A9-8AE2E92086D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55D717E8-6043-487C-83A9-8AE2E92086D7}.Release|Any CPU.Build.0 = Release|Any CPU + {A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}.Release|Any CPU.Build.0 = Release|Any CPU + {049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {049C94B7-EC09-4511-B6BC-21DE2C9C54E1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -168,21 +142,17 @@ Global {23D83C90-BC4D-4D55-982E-67A55EE97D0D} = {FCAB2F70-846A-4C13-8332-48B70C792256} {477711F6-C7D5-45D5-8E8B-A1810DD307D1} = {672E561C-44EA-43EE-8C9D-9E70D8DFB80F} {E054D012-2AA7-4B70-9CDC-253FF510B0C8} = {672E561C-44EA-43EE-8C9D-9E70D8DFB80F} - {18BFFAE7-E697-4BA8-91D8-DA725F5C8188} = {631CE917-1F5D-42D9-81A4-575C13B84826} - {F59896AE-4A84-4AA8-BB45-7BFED102D14E} = {631CE917-1F5D-42D9-81A4-575C13B84826} - {994036C2-1EFA-46AF-8531-F0C5D4DB22C1} = {631CE917-1F5D-42D9-81A4-575C13B84826} {DBA5FE1B-100F-460F-B192-320B5C85949C} = {672E561C-44EA-43EE-8C9D-9E70D8DFB80F} {7BD651E7-3B5C-4118-963C-629C34F30258} = {FCAB2F70-846A-4C13-8332-48B70C792256} - {9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1} = {631CE917-1F5D-42D9-81A4-575C13B84826} - {8AA4B104-864A-4188-A1AE-481E71D4D533} = {631CE917-1F5D-42D9-81A4-575C13B84826} {6E3F2DD4-6AE5-49B2-B5E4-04B21E073B4F} = {4A930AE8-3A32-48A4-BCDB-0F55FA53AE4B} {FAF13809-A3BA-417D-AC25-B682011AB655} = {4A930AE8-3A32-48A4-BCDB-0F55FA53AE4B} {A19EC5EA-3E4F-47CD-A9B8-802663E9F489} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} {3649B470-E632-41F7-A7B9-5331B21B3560} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} {A1C3BA6A-7055-4AFD-9EB3-3B9019D3E7A4} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} - {1D6D928A-AA0F-40F6-8930-47B695919104} = {137019F4-2B62-4DD8-B2F8-0F5067205101} - {7435EFBA-471C-4BFB-A306-EB9CDF375585} = {137019F4-2B62-4DD8-B2F8-0F5067205101} - {3AED54D4-4674-46E0-9289-099019E82A70} = {137019F4-2B62-4DD8-B2F8-0F5067205101} + {9FFE063D-3093-4C0A-AFAA-85D34E5E4AE1} = {110C16ED-A11D-4B5A-ABB2-0E0F4692C77A} + {55D717E8-6043-487C-83A9-8AE2E92086D7} = {873BFCC4-435D-44D7-8287-1FB1574B2319} + {A851D896-AC63-4DC0-98FC-9E1EEA5DACE5} = {873BFCC4-435D-44D7-8287-1FB1574B2319} + {049C94B7-EC09-4511-B6BC-21DE2C9C54E1} = {873BFCC4-435D-44D7-8287-1FB1574B2319} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0E72B357-9E1E-43B5-9868-8D2B74CB2AF0} diff --git a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs index b2272acfb3..eadff21efa 100644 --- a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs +++ b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs @@ -22,13 +22,11 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio switch (dbServer.Provider) { case DatabaseServerProvider.SqlServer: - usings.Add("using Nox.DatabaseProvider.SqlServer;"); usings.Add("using Nox.Types.EntityFramework.SqlServer;"); dbConfigurator = "SqlServerDatabaseConfigurator"; dbProvider = "SqlServerDatabaseProvider"; break; case DatabaseServerProvider.Postgres: - usings.Add("using Nox.DatabaseProvider.Postgres;"); usings.Add("using Nox.Types.EntityFramework.Postgres;"); dbConfigurator = "PostgresDatabaseConfigurator"; dbProvider = "PostgresDatabaseProvider"; @@ -38,7 +36,6 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio code.AppendLine("using Microsoft.EntityFrameworkCore;"); code.AppendLine("using Nox;"); - code.AppendLine("using Nox.DatabaseProvider;"); code.AppendLines(usings.ToArray()); code.AppendLine("using Nox.Types.EntityFramework.vNext;"); code.AppendLine("using SampleWebApp.Infrastructure.Persistence;"); diff --git a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs index f5893a1af7..9858831c4e 100644 --- a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs +++ b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs @@ -1,4 +1,4 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; using Nox.Generator.Common; using Nox.Solution; @@ -30,7 +30,6 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio private static void AddUsing(CodeBuilder code, string solutionNameSpace) { code.AppendLine(@"using Microsoft.EntityFrameworkCore;"); - code.AppendLine(@"using Nox.DatabaseProvider;"); code.AppendLine(@"using Nox.Solution;"); code.AppendLine(@"using Nox.Types.EntityFramework.vNext;"); code.AppendLine(@"using SampleWebApp.Domain;"); diff --git a/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs b/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs index 96d693ccde..e827848957 100644 --- a/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs +++ b/src/Nox.Lib/Extensions/ServiceCollectionExtension.cs @@ -1,6 +1,5 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; -using Nox.DatabaseProvider; using Nox.Solution; namespace Nox; diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index bafbe1c097..a0549c9f7d 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,16 +36,11 @@ - - - - - diff --git a/src/Nox.Types.EntityFramework.Postgres/Nox.Types.EntityFramework.Postgres.csproj b/src/Nox.Types.EntityFramework.Postgres/Nox.Types.EntityFramework.Postgres.csproj index 1706c7d4e9..e52cb19ef3 100644 --- a/src/Nox.Types.EntityFramework.Postgres/Nox.Types.EntityFramework.Postgres.csproj +++ b/src/Nox.Types.EntityFramework.Postgres/Nox.Types.EntityFramework.Postgres.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs deleted file mode 100644 index a19adf6808..0000000000 --- a/src/Nox.Types.EntityFramework.Postgres/PostgresDatabaseConfigurator.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Nox.Types.EntityFramework.vNext; -using Nox.Types.EntityFramework.vNext.Types; - -namespace Nox.Types.EntityFramework.Postgres; - -public sealed class PostgresDatabaseConfigurator: NoxDatabaseConfigurator -{ - private static readonly Dictionary TypesConfiguration = - new() - { - { NoxType.Text, new PostgresTextDatabaseConfiguration() }, //Use Postgres Implementation - { NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation - { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation - }; - - public PostgresDatabaseConfigurator() : base(TypesConfiguration) - { - } -} \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj b/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj index 9facf826ec..4766c3465b 100644 --- a/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj +++ b/src/Nox.Types.EntityFramework.SqlServer/Nox.Types.EntityFramework.SqlServer.csproj @@ -20,7 +20,7 @@ - + \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.SqlServer/SqlServerDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework.SqlServer/SqlServerDatabaseConfigurator.cs deleted file mode 100644 index 9ef65265ac..0000000000 --- a/src/Nox.Types.EntityFramework.SqlServer/SqlServerDatabaseConfigurator.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Nox.Types.EntityFramework.vNext; -using Nox.Types.EntityFramework.vNext.Types; - -namespace Nox.Types.EntityFramework.SqlServer; - -public sealed class SqlServerDatabaseConfigurator : NoxDatabaseConfigurator -{ - //We could use the container to manage this - private static readonly Dictionary _typesConfiguration = - new() - { - { NoxType.Text, new SqlServerTextDatabaseConfigurator() }, //Use MySql Implementation - { NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation - { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation - }; - - public SqlServerDatabaseConfigurator() : base(_typesConfiguration) - { - } -} \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.Sqlite/Nox.Types.EntityFramework.Sqlite.csproj b/src/Nox.Types.EntityFramework.Sqlite/Nox.Types.EntityFramework.Sqlite.csproj index 8cadc6e7fa..112adddf43 100644 --- a/src/Nox.Types.EntityFramework.Sqlite/Nox.Types.EntityFramework.Sqlite.csproj +++ b/src/Nox.Types.EntityFramework.Sqlite/Nox.Types.EntityFramework.Sqlite.csproj @@ -19,8 +19,4 @@ - - - - diff --git a/src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs b/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs similarity index 86% rename from src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs rename to src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs index 2f0ee81f08..7068718acf 100644 --- a/src/Nox.DatabaseProvider/NoxDatabaseProviderException.cs +++ b/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs @@ -1,4 +1,4 @@ -namespace Nox.DatabaseProvider; +namespace Nox.Types.EntityFramework.vNext.Exceptions; [Serializable] public class NoxDatabaseProviderException : Exception diff --git a/src/Nox.Types.EntityFramework.vNext/NoxEntityFrameworkException.cs b/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs similarity index 87% rename from src/Nox.Types.EntityFramework.vNext/NoxEntityFrameworkException.cs rename to src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs index 99894ea647..fe3fe4211b 100644 --- a/src/Nox.Types.EntityFramework.vNext/NoxEntityFrameworkException.cs +++ b/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs @@ -1,4 +1,4 @@ -namespace Nox.Types.EntityFramework.vNext +namespace Nox.Types.EntityFramework.vNext.Exceptions { public class NoxEntityFrameworkException : Exception { diff --git a/src/Nox.Types.EntityFramework.vNext/INoxDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework.vNext/INoxDatabaseConfigurator.cs deleted file mode 100644 index b65af67a70..0000000000 --- a/src/Nox.Types.EntityFramework.vNext/INoxDatabaseConfigurator.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Nox.Solution; - - -namespace Nox.Types.EntityFramework.vNext -{ - public interface INoxDatabaseConfigurator - { - void ConfigureEntity(EntityTypeBuilder builder, Entity entity); - } -} \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj b/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj index c46f8721ad..a539c67be1 100644 --- a/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj +++ b/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj @@ -24,4 +24,8 @@ + + + + \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseConfigurator.cs new file mode 100644 index 0000000000..a43a452cd2 --- /dev/null +++ b/src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseConfigurator.cs @@ -0,0 +1,9 @@ +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Nox.Solution; + +namespace Nox.Types.EntityFramework.Abstractions; + +public interface INoxDatabaseConfigurator +{ + void ConfigureEntity(EntityTypeBuilder builder, Entity entity); +} \ No newline at end of file diff --git a/src/Nox.DatabaseProvider/INoxDatabaseProvider.cs b/src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseProvider.cs similarity index 89% rename from src/Nox.DatabaseProvider/INoxDatabaseProvider.cs rename to src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseProvider.cs index 109e302eb8..93519c5904 100644 --- a/src/Nox.DatabaseProvider/INoxDatabaseProvider.cs +++ b/src/Nox.Types.EntityFramework/Abstractions/INoxDatabaseProvider.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; using Nox.Solution; -namespace Nox.DatabaseProvider +namespace Nox.Types.EntityFramework.Abstractions { public interface INoxDatabaseProvider { diff --git a/src/Nox.Types.EntityFramework.vNext/Types/INoxTypeDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Abstractions/INoxTypeDatabaseConfigurator.cs similarity index 82% rename from src/Nox.Types.EntityFramework.vNext/Types/INoxTypeDatabaseConfigurator.cs rename to src/Nox.Types.EntityFramework/Abstractions/INoxTypeDatabaseConfigurator.cs index 248ad987ee..1f8f39dcdb 100644 --- a/src/Nox.Types.EntityFramework.vNext/Types/INoxTypeDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework/Abstractions/INoxTypeDatabaseConfigurator.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nox.Solution; -namespace Nox.Types.EntityFramework.vNext.Types; +namespace Nox.Types.EntityFramework.Abstractions; public interface INoxTypeDatabaseConfigurator { diff --git a/src/Nox.Types.EntityFramework.vNext/Types/MoneyDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Configurators/MoneyDatabaseConfigurator.cs similarity index 86% rename from src/Nox.Types.EntityFramework.vNext/Types/MoneyDatabaseConfigurator.cs rename to src/Nox.Types.EntityFramework/Configurators/MoneyDatabaseConfigurator.cs index 634e95c765..27c0d023c5 100644 --- a/src/Nox.Types.EntityFramework.vNext/Types/MoneyDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework/Configurators/MoneyDatabaseConfigurator.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nox.Solution; +using Nox.Types.EntityFramework.Abstractions; -namespace Nox.Types.EntityFramework.vNext.Types; +namespace Nox.Types.EntityFramework.Configurators; public class MoneyDatabaseConfigurator : INoxTypeDatabaseConfigurator { diff --git a/src/Nox.Types.EntityFramework.vNext/NoxDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Configurators/NoxDatabaseConfigurator.cs similarity index 95% rename from src/Nox.Types.EntityFramework.vNext/NoxDatabaseConfigurator.cs rename to src/Nox.Types.EntityFramework/Configurators/NoxDatabaseConfigurator.cs index d9dbe4836c..d1be0f1db3 100644 --- a/src/Nox.Types.EntityFramework.vNext/NoxDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework/Configurators/NoxDatabaseConfigurator.cs @@ -1,8 +1,8 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nox.Solution; -using Nox.Types.EntityFramework.vNext.Types; +using Nox.Types.EntityFramework.Abstractions; -namespace Nox.Types.EntityFramework.vNext +namespace Nox.Types.EntityFramework.Configurators { public abstract class NoxDatabaseConfigurator : INoxDatabaseConfigurator { diff --git a/src/Nox.Types.EntityFramework.vNext/Types/NumberDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Configurators/NumberDatabaseConfigurator.cs similarity index 95% rename from src/Nox.Types.EntityFramework.vNext/Types/NumberDatabaseConfigurator.cs rename to src/Nox.Types.EntityFramework/Configurators/NumberDatabaseConfigurator.cs index dbf8f5aa68..be6d6730f9 100644 --- a/src/Nox.Types.EntityFramework.vNext/Types/NumberDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework/Configurators/NumberDatabaseConfigurator.cs @@ -1,8 +1,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nox.Solution; +using Nox.Types.EntityFramework.Abstractions; using Nox.Types.EntityFramework.Types; -namespace Nox.Types.EntityFramework.vNext.Types; +namespace Nox.Types.EntityFramework.Configurators; public class NumberDatabaseConfigurator : INoxTypeDatabaseConfigurator { diff --git a/src/Nox.Types.EntityFramework.vNext/Types/TextDatabaseConfigurator.cs b/src/Nox.Types.EntityFramework/Configurators/TextDatabaseConfigurator.cs similarity index 91% rename from src/Nox.Types.EntityFramework.vNext/Types/TextDatabaseConfigurator.cs rename to src/Nox.Types.EntityFramework/Configurators/TextDatabaseConfigurator.cs index 864ddf6e70..a184bc5194 100644 --- a/src/Nox.Types.EntityFramework.vNext/Types/TextDatabaseConfigurator.cs +++ b/src/Nox.Types.EntityFramework/Configurators/TextDatabaseConfigurator.cs @@ -1,9 +1,10 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Nox.Solution; +using Nox.Types.EntityFramework.Abstractions; using Nox.Types.EntityFramework.Types; -namespace Nox.Types.EntityFramework.vNext.Types; +namespace Nox.Types.EntityFramework.Configurators; public class TextDatabaseConfigurator : INoxTypeDatabaseConfigurator { diff --git a/src/Nox.Types.EntityFramework.vNext/FluentApiUtil.cs b/src/Nox.Types.EntityFramework/FluentApiUtil.cs similarity index 90% rename from src/Nox.Types.EntityFramework.vNext/FluentApiUtil.cs rename to src/Nox.Types.EntityFramework/FluentApiUtil.cs index 0295ecb5fa..e9b935f8ed 100644 --- a/src/Nox.Types.EntityFramework.vNext/FluentApiUtil.cs +++ b/src/Nox.Types.EntityFramework/FluentApiUtil.cs @@ -1,4 +1,4 @@ -namespace Nox.Types.EntityFramework.vNext; +namespace Nox.Types.EntityFramework; public static class FluentApiUtil { diff --git a/src/Nox.Types.EntityFramework/Nox.Types.EntityFramework.csproj b/src/Nox.Types.EntityFramework/Nox.Types.EntityFramework.csproj index edb545e901..2ff5b68402 100644 --- a/src/Nox.Types.EntityFramework/Nox.Types.EntityFramework.csproj +++ b/src/Nox.Types.EntityFramework/Nox.Types.EntityFramework.csproj @@ -21,10 +21,12 @@ - + + + diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs index 2734cb8cea..3450124405 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs @@ -4,9 +4,7 @@ using Microsoft.EntityFrameworkCore; using Nox; -using Nox.DatabaseProvider; -using Nox.DatabaseProvider.Postgres; -using Nox.Types.EntityFramework.Postgres; +using Nox.Types.EntityFramework.SqlServer; using Nox.Types.EntityFramework.vNext; using SampleWebApp.Infrastructure.Persistence; @@ -16,8 +14,8 @@ public static IServiceCollection AddNox(this IServiceCollection services) { services.AddNoxLib(); services.AddSingleton>(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddDbContext(); var tmpProvider = services.BuildServiceProvider(); var dbContext = tmpProvider.GetRequiredService(); diff --git a/src/SampleWebApp/SampleWebApp.csproj b/src/SampleWebApp/SampleWebApp.csproj index db5d7991b7..2f790d2c0d 100644 --- a/src/SampleWebApp/SampleWebApp.csproj +++ b/src/SampleWebApp/SampleWebApp.csproj @@ -36,8 +36,6 @@ - - From 51550d37b19b1a070872840a68b2648a5cae5b43 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 14:12:26 +0200 Subject: [PATCH 13/18] - added changes to generators --- .../Common/ServiceCollectionExtensionGenerator.cs | 11 ++++------- .../DbContextGenerator/DbContextGenerator.cs | 7 ++----- src/Nox.Lib/Nox.Lib.csproj | 3 +++ .../NoxServiceCollectionExtension.g.cs | 8 ++++---- .../SampleWebAppDbContext.g.cs | 8 ++------ src/SampleWebApp/Program.cs | 1 - src/SampleWebApp/SampleWebApp.csproj | 6 ++---- tests/Nox.Types.Tests/Nox.Types.Tests.csproj | 2 +- 8 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs index eadff21efa..85a31f4aed 100644 --- a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs +++ b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs @@ -13,7 +13,6 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio var code = new CodeBuilder($"NoxServiceCollectionExtension.g.cs", context); var usings = new List(); - var dbConfigurator = ""; var dbProvider = ""; if (solution.Infrastructure?.Persistence is { DatabaseServer: not null }) @@ -22,13 +21,11 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio switch (dbServer.Provider) { case DatabaseServerProvider.SqlServer: - usings.Add("using Nox.Types.EntityFramework.SqlServer;"); - dbConfigurator = "SqlServerDatabaseConfigurator"; + usings.Add("using Nox.DatabaseProvider.SqlServer;"); dbProvider = "SqlServerDatabaseProvider"; break; case DatabaseServerProvider.Postgres: - usings.Add("using Nox.Types.EntityFramework.Postgres;"); - dbConfigurator = "PostgresDatabaseConfigurator"; + usings.Add("using Nox.DatabaseProvider.Postgres;"); dbProvider = "PostgresDatabaseProvider"; break; } @@ -37,7 +34,7 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio code.AppendLine("using Microsoft.EntityFrameworkCore;"); code.AppendLine("using Nox;"); code.AppendLines(usings.ToArray()); - code.AppendLine("using Nox.Types.EntityFramework.vNext;"); + code.AppendLine("using Nox.Types.EntityFramework.Abstractions;"); code.AppendLine("using SampleWebApp.Infrastructure.Persistence;"); code.AppendLine(); @@ -50,7 +47,7 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio { var dbContextName = $"{solution.Name}DbContext"; code.AppendLine($"services.AddSingleton>();"); - code.AppendLine($"services.AddSingleton();"); + code.AppendLine($"services.AddSingleton();"); code.AppendLine($"services.AddSingleton();"); code.AppendLine($"services.AddDbContext<{dbContextName}>();"); code.AppendLine("var tmpProvider = services.BuildServiceProvider();"); diff --git a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs index 9858831c4e..c33f8b5205 100644 --- a/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs +++ b/src/Nox.Generator/Infrastructure/Persistence/DbContextGenerator/DbContextGenerator.cs @@ -31,7 +31,7 @@ private static void AddUsing(CodeBuilder code, string solutionNameSpace) { code.AppendLine(@"using Microsoft.EntityFrameworkCore;"); code.AppendLine(@"using Nox.Solution;"); - code.AppendLine(@"using Nox.Types.EntityFramework.vNext;"); + code.AppendLine(@"using Nox.Types.EntityFramework.Abstractions;"); code.AppendLine(@"using SampleWebApp.Domain;"); code.AppendLine(); code.AppendLine($"namespace {solutionNameSpace}.Infrastructure.Persistence;"); @@ -46,19 +46,16 @@ private static void AddClass(CodeBuilder code, NoxSolution solution, string dbCo code.StartBlock(); code.AppendLine("private readonly NoxSolution _noxSolution;"); - code.AppendLine("private readonly INoxDatabaseConfigurator _databaseConfigurator;"); code.AppendLine("private readonly INoxDatabaseProvider _dbProvider;"); code.AppendLine(); code.AppendLine($"public {dbContextName}("); code.AppendLine($" DbContextOptions<{dbContextName}> options,"); code.AppendLine(" NoxSolution noxSolution,"); - code.AppendLine(" INoxDatabaseConfigurator databaseConfigurator,"); code.AppendLine(" INoxDatabaseProvider databaseProvider"); code.AppendLine(") : base(options)"); code.StartBlock(); code.AppendLine(" _noxSolution = noxSolution;"); - code.AppendLine(" _databaseConfigurator = databaseConfigurator;"); code.AppendLine(" _dbProvider = databaseProvider;"); code.EndBlock(); code.AppendLine(); @@ -114,7 +111,7 @@ private static void AddOnModelCreating(CodeBuilder code, string solutionName) code.AppendLine(); code.AppendLine("if (type != null)"); code.StartBlock(); - code.AppendLine("_databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity);"); + code.AppendLine("((INoxDatabaseConfigurator)_dbProvider).ConfigureEntity(modelBuilder.Entity(type), entity);"); code.EndBlock(); code.EndBlock(); code.AppendLine(); diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index a0549c9f7d..b9dac80026 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,6 +36,9 @@ + + + diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs index 3450124405..a67093eb82 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs @@ -4,8 +4,8 @@ using Microsoft.EntityFrameworkCore; using Nox; -using Nox.Types.EntityFramework.SqlServer; -using Nox.Types.EntityFramework.vNext; +using Nox.DatabaseProvider.Postgres; +using Nox.Types.EntityFramework.Abstractions; using SampleWebApp.Infrastructure.Persistence; public static class NoxServiceCollectionExtension @@ -14,8 +14,8 @@ public static IServiceCollection AddNox(this IServiceCollection services) { services.AddNoxLib(); services.AddSingleton>(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddDbContext(); var tmpProvider = services.BuildServiceProvider(); var dbContext = tmpProvider.GetRequiredService(); diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs index 2a70b3bf20..eddae13614 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs @@ -3,9 +3,8 @@ #nullable enable using Microsoft.EntityFrameworkCore; -using Nox.DatabaseProvider; using Nox.Solution; -using Nox.Types.EntityFramework.vNext; +using Nox.Types.EntityFramework.Abstractions; using SampleWebApp.Domain; namespace SampleWebApp.Infrastructure.Persistence; @@ -13,18 +12,15 @@ namespace SampleWebApp.Infrastructure.Persistence; public partial class SampleWebAppDbContext : DbContext { private readonly NoxSolution _noxSolution; - private readonly INoxDatabaseConfigurator _databaseConfigurator; private readonly INoxDatabaseProvider _dbProvider; public SampleWebAppDbContext( DbContextOptions options, NoxSolution noxSolution, - INoxDatabaseConfigurator databaseConfigurator, INoxDatabaseProvider databaseProvider ) : base(options) { _noxSolution = noxSolution; - _databaseConfigurator = databaseConfigurator; _dbProvider = databaseProvider; } @@ -56,7 +52,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) if (type != null) { - _databaseConfigurator.ConfigureEntity(modelBuilder.Entity(type), entity); + ((INoxDatabaseConfigurator)_dbProvider).ConfigureEntity(modelBuilder.Entity(type), entity); } } diff --git a/src/SampleWebApp/Program.cs b/src/SampleWebApp/Program.cs index 6da67fba54..97fd8a950a 100644 --- a/src/SampleWebApp/Program.cs +++ b/src/SampleWebApp/Program.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using Nox; using Nox.Solution; -using Nox.Types.EntityFramework.Sqlite; using SampleWebApp.Infrastructure.Persistence; var builder = WebApplication.CreateBuilder(args); diff --git a/src/SampleWebApp/SampleWebApp.csproj b/src/SampleWebApp/SampleWebApp.csproj index 2f790d2c0d..be6247ad4d 100644 --- a/src/SampleWebApp/SampleWebApp.csproj +++ b/src/SampleWebApp/SampleWebApp.csproj @@ -33,9 +33,11 @@ + + @@ -53,8 +55,4 @@ - - - - \ No newline at end of file diff --git a/tests/Nox.Types.Tests/Nox.Types.Tests.csproj b/tests/Nox.Types.Tests/Nox.Types.Tests.csproj index 8946569931..3b21412697 100644 --- a/tests/Nox.Types.Tests/Nox.Types.Tests.csproj +++ b/tests/Nox.Types.Tests/Nox.Types.Tests.csproj @@ -12,7 +12,7 @@ - + From 9a8f17ad3b7ee6a161a09d209156f9707e32d16a Mon Sep 17 00:00:00 2001 From: Ricardo Rocha Date: Wed, 5 Jul 2023 14:29:59 +0100 Subject: [PATCH 14/18] update name for SqlServer --- src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs index 7e7e1af48f..38d24e95f0 100644 --- a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs +++ b/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs @@ -13,7 +13,7 @@ public class SqlServerDatabaseProvider: NoxDatabaseConfigurator, INoxDatabasePro private static readonly Dictionary TypesConfiguration = new() { - { NoxType.Text, new SqlServerTextDatabaseConfigurator() }, //Use MySql Implementation + { NoxType.Text, new SqlServerTextDatabaseConfigurator() }, //Use SqlServer Implementation { NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation { NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation }; From 7fd04a5366a35f7e9ab064ce9ab39143bdd5efb7 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 16:12:43 +0200 Subject: [PATCH 15/18] Added Exceptions pack --- .../Exceptions/NoxEntityFrameworkException.cs | 19 ------------ .../Nox.Types.EntityFramework.vNext.csproj | 31 ------------------- .../NoxDatabaseProviderException.cs | 2 +- .../Exceptions/NoxEntityFrameworkException.cs | 18 +++++++++++ .../NoxServiceCollectionExtension.g.cs | 6 ++-- src/SampleWebApp/SampleWebApp.csproj | 1 + 6 files changed, 23 insertions(+), 54 deletions(-) delete mode 100644 src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs delete mode 100644 src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj rename src/{Nox.Types.EntityFramework.vNext => Nox.Types.EntityFramework}/Exceptions/NoxDatabaseProviderException.cs (86%) create mode 100644 src/Nox.Types.EntityFramework/Exceptions/NoxEntityFrameworkException.cs diff --git a/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs b/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs deleted file mode 100644 index fe3fe4211b..0000000000 --- a/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxEntityFrameworkException.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Nox.Types.EntityFramework.vNext.Exceptions -{ - public class NoxEntityFrameworkException : Exception - { - public NoxEntityFrameworkException() - { - } - - public NoxEntityFrameworkException(string message) - : base(message) - { - } - - public NoxEntityFrameworkException(string message, Exception inner) - : base(message, inner) - { - } - } -} \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj b/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj deleted file mode 100644 index a539c67be1..0000000000 --- a/src/Nox.Types.EntityFramework.vNext/Nox.Types.EntityFramework.vNext.csproj +++ /dev/null @@ -1,31 +0,0 @@ - - - - net7.0 - enable - enable - - - - True - - - - True - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs b/src/Nox.Types.EntityFramework/Exceptions/NoxDatabaseProviderException.cs similarity index 86% rename from src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs rename to src/Nox.Types.EntityFramework/Exceptions/NoxDatabaseProviderException.cs index 7068718acf..db9e3c7747 100644 --- a/src/Nox.Types.EntityFramework.vNext/Exceptions/NoxDatabaseProviderException.cs +++ b/src/Nox.Types.EntityFramework/Exceptions/NoxDatabaseProviderException.cs @@ -1,4 +1,4 @@ -namespace Nox.Types.EntityFramework.vNext.Exceptions; +namespace Nox.Types.EntityFramework.Exceptions; [Serializable] public class NoxDatabaseProviderException : Exception diff --git a/src/Nox.Types.EntityFramework/Exceptions/NoxEntityFrameworkException.cs b/src/Nox.Types.EntityFramework/Exceptions/NoxEntityFrameworkException.cs new file mode 100644 index 0000000000..5f2c74fdf8 --- /dev/null +++ b/src/Nox.Types.EntityFramework/Exceptions/NoxEntityFrameworkException.cs @@ -0,0 +1,18 @@ +namespace Nox.Types.EntityFramework.Exceptions; + +public class NoxEntityFrameworkException : Exception +{ + public NoxEntityFrameworkException() + { + } + + public NoxEntityFrameworkException(string message) + : base(message) + { + } + + public NoxEntityFrameworkException(string message, Exception inner) + : base(message, inner) + { + } +} \ No newline at end of file diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs index a67093eb82..7a1cd1084e 100644 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs +++ b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs @@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore; using Nox; -using Nox.DatabaseProvider.Postgres; +using Nox.DatabaseProvider.SqlServer; using Nox.Types.EntityFramework.Abstractions; using SampleWebApp.Infrastructure.Persistence; @@ -14,8 +14,8 @@ public static IServiceCollection AddNox(this IServiceCollection services) { services.AddNoxLib(); services.AddSingleton>(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddDbContext(); var tmpProvider = services.BuildServiceProvider(); var dbContext = tmpProvider.GetRequiredService(); diff --git a/src/SampleWebApp/SampleWebApp.csproj b/src/SampleWebApp/SampleWebApp.csproj index be6247ad4d..01fdb16c0d 100644 --- a/src/SampleWebApp/SampleWebApp.csproj +++ b/src/SampleWebApp/SampleWebApp.csproj @@ -5,6 +5,7 @@ enable 10.0 enable + d3ab7cc3-3b79-49dd-bd9e-9d3ad2c7aaa4 From 99bb46208672495b87bbe6794513f527b88909d3 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 16:30:26 +0200 Subject: [PATCH 16/18] - regenerated files --- .../SqliteDatabaseConfigurator.cs | 20 --- .../SqliteDatabaseProvider.cs | 38 +++++ .../AuditableEntityBase.g.cs | 40 ----- .../CountriesApiController.g.cs | 58 -------- .../CountriesController.g.cs | 140 ------------------ .../Country.g.cs | 91 ------------ .../CountryDto.g.cs | 23 --- .../CountryInfo.g.cs | 26 ---- .../CountryLocalNames.g.cs | 21 --- .../CountryLocalNamesController.g.cs | 140 ------------------ .../CountryNameChangedAppEvent.g.cs | 28 ---- .../CountryNameUpdatedEvent.g.cs | 27 ---- .../CurrenciesController.g.cs | 140 ------------------ .../Currency.g.cs | 33 ----- .../EntityBase.g.cs | 18 --- .../Generator.g.cs | 11 -- .../GetCountriesByContinentQuery.g.cs | 32 ---- .../NoxServiceCollectionExtension.g.cs | 25 ---- .../ODataConfiguration.g.cs | 34 ----- .../SampleWebAppDbContext.g.cs | 64 -------- .../Nox.Generator.NoxCodeGenerator/Store.g.cs | 31 ---- .../StoresController.g.cs | 140 ------------------ .../UpdatePopulationStatistics.g.cs | 20 --- ...opulationStatisticsCommandHandlerBase.g.cs | 51 ------- .../Models/TestDatabaseWebAppDbContext.g.cs | 2 +- .../Database/SqliteIntegrationTests.cs | 2 +- .../Database/SqliteTestBase.cs | 10 +- .../Nox.Generator.Tests.csproj | 3 +- 28 files changed, 46 insertions(+), 1222 deletions(-) delete mode 100644 src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs create mode 100644 src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs delete mode 100644 src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs diff --git a/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs b/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs deleted file mode 100644 index 7f2eb7ddcd..0000000000 --- a/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseConfigurator.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Nox.Types; -using Nox.Types.EntityFramework.Abstractions; -using Nox.Types.EntityFramework.Configurators; - -namespace Nox.DatabaseProvider.Sqlite; - -public sealed class SqliteDatabaseConfigurator : NoxDatabaseConfigurator -{ - private static readonly Dictionary _typesConfiguration = new() - { - // Use default implementation for all types - { NoxType.Text, new TextDatabaseConfigurator() }, - { NoxType.Number, new NumberDatabaseConfigurator() }, - { NoxType.Money, new MoneyDatabaseConfigurator() } - }; - - public SqliteDatabaseConfigurator() : base(_typesConfiguration) - { - } -} \ No newline at end of file diff --git a/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs b/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs new file mode 100644 index 0000000000..a83d9fd064 --- /dev/null +++ b/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using Nox.Solution; +using Nox.Types; +using Nox.Types.EntityFramework.Abstractions; +using Nox.Types.EntityFramework.Configurators; + +namespace Nox.DatabaseProvider.Sqlite; + +public sealed class SqliteDatabaseProvider : NoxDatabaseConfigurator, INoxDatabaseProvider +{ + private static readonly Dictionary TypesConfiguration = new() + { + // Use default implementation for all types + { NoxType.Text, new TextDatabaseConfigurator() }, + { NoxType.Number, new NumberDatabaseConfigurator() }, + { NoxType.Money, new MoneyDatabaseConfigurator() } + }; + + public SqliteDatabaseProvider() : base(TypesConfiguration) + { + } + + public string ConnectionString { get; set; } = string.Empty; + public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer) + { + throw new NotImplementedException(); + } + + public string ToTableNameForSql(string table, string schema) + { + throw new NotImplementedException(); + } + + public string ToTableNameForSqlRaw(string table, string schema) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs deleted file mode 100644 index a5908d5ce9..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/AuditableEntityBase.g.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Generated - -#nullable enable - -using System; - -namespace SampleWebApp.Domain; - -public partial class AuditableEntityBase -{ - /// - /// The date and time when this entity was first created (in Coordinated Universal Time). - /// - public DateTime CreatedAtUtc {get; set;} - - /// - /// The user that created the entity. - /// - public string? CreatedBy {get; set;} - - /// - /// The date and time when this entity was last updated (in Coordinated Universal Time). - /// - public DateTime? UpdatedAtUtc {get; set;} - - /// - /// The user that last updated the entity. - /// - public string? UpdatedBy {get; set;} - - /// - /// The date and time when this entity was deleted (in Coordinated Universal Time). - /// - public DateTime? DeletedAtUtc {get; set;} - - /// - /// The user that deleted the entity. - /// - public string? DeletedBy {get; set;} -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs deleted file mode 100644 index c35ca25a10..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesApiController.g.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using Microsoft.AspNetCore.Mvc; -using SampleWebApp.Application; -using SampleWebApp.Application.DataTransferObjects; - -namespace SampleWebApp.Presentation.Rest; - -/// -/// Controller for Country entity. The list of countries. -/// -[ApiController] -[Route("Countries")] -public partial class CountriesApiController : ControllerBase -{ - - /// - /// Returns a list of countries for a given continent. - /// - protected GetCountriesByContinentQuery GetCountriesByContinent { get; set; } = null!; - - /// - /// Instructs the service to collect updated population statistics. - /// - protected UpdatePopulationStatisticsCommandHandlerBase UpdatePopulationStatistics { get; set; } = null!; - - public CountriesApiController( - GetCountriesByContinentQuery getCountriesByContinent, - UpdatePopulationStatisticsCommandHandlerBase updatePopulationStatistics - ) - { - GetCountriesByContinent = getCountriesByContinent; - UpdatePopulationStatistics = updatePopulationStatistics; - } - - /// - /// Returns a list of countries for a given continent. - /// - [HttpGet("GetCountriesByContinent")] - public async Task GetCountriesByContinentAsync(Text continentName) - { - var result = await GetCountriesByContinent.ExecuteAsync(continentName); - return Results.Ok(result); - } - - /// - /// Instructs the service to collect updated population statistics. - /// - [HttpPost("UpdatePopulationStatistics")] - public async Task UpdatePopulationStatisticsAsync(UpdatePopulationStatistics command) - { - var result = await UpdatePopulationStatistics.ExecuteAsync(command); - return result.IsSuccess ? Results.Ok(result) : Results.BadRequest(result); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs deleted file mode 100644 index 4235f60732..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountriesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CountriesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CountriesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Countries); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Countries.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Country country) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Countries.Add(country); - - await _databaseContext.SaveChangesAsync(); - - return Created(country); - } - - public async Task Put([FromRoute] string key, [FromBody] Country updatedCountry) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCountry.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCountry).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCountry); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta country) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Countries.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - country.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CountryExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Countries.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var country = await _databaseContext.Countries.FindAsync(parsedKey); - if (country == null) - { - return NotFound(); - } - - _databaseContext.Countries.Remove(country); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs deleted file mode 100644 index 7fde1e2354..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Country.g.cs +++ /dev/null @@ -1,91 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The list of countries. -/// -public partial class Country : AuditableEntityBase -{ - - /// - /// (Optional) - /// - public Text Id { get; set; } = null!; - - /// - /// The country's common name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// The country's official name (required). - /// - public Text FormalName { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-3 code (required). - /// - public Text AlphaCode3 { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-2 code (required). - /// - public Text AlphaCode2 { get; set; } = null!; - - /// - /// The country's official ISO 4217 alpha-3 code (required). - /// - public Number NumericCode { get; set; } = null!; - - /// - /// The country's phone dialing codes (comma-delimited) (optional). - /// - public Text? DialingCodes { get; set; } = null!; - - /// - /// The capital city of the country (optional). - /// - public Text? Capital { get; set; } = null!; - - /// - /// Noun denoting the natives of the country (optional). - /// - public Text? Demonym { get; set; } = null!; - - /// - /// Country area in square kilometers (required). - /// - public Number AreaInSquareKilometres { get; set; } = null!; - - /// - /// The region the country is in (required). - /// - public Text GeoRegion { get; set; } = null!; - - /// - /// The sub-region the country is in (required). - /// - public Text GeoSubRegion { get; set; } = null!; - - /// - /// The world region the country is in (required). - /// - public Text GeoWorldRegion { get; set; } = null!; - - /// - /// The estimated population of the country (optional). - /// - public Number? Population { get; set; } = null!; - - /// - /// The top level internet domains regitered to the country (comma-delimited) (optional). - /// - public Text? TopLevelDomains { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs deleted file mode 100644 index fbafdeb1f7..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryDto.g.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - -/// -/// Dto for country information. -/// -public partial class CountryDto : IDynamicDto -{ - - /// - /// The identity of the country, the Iso Alpha 2 code. - /// - public Text? Id { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs deleted file mode 100644 index 15779a0736..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryInfo.g.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - -public partial class CountryInfo : IDynamicDto -{ - - /// - /// The country's Id. - /// - public CountryCode2? CountryId { get; set; } = null!; - - - /// - /// The country name. - /// - public Text? CountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs deleted file mode 100644 index 79c7b172ac..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNames.g.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The name of a country in other languages. -/// -public partial class CountryLocalNames : AuditableEntityBase -{ - - /// - /// (Optional) - /// - public Text Id { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs deleted file mode 100644 index 1cd291bdeb..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryLocalNamesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CountryLocalNamesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CountryLocalNamesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.CountryLocalNames); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.CountryLocalNames.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(CountryLocalNames countrylocalnames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.CountryLocalNames.Add(countrylocalnames); - - await _databaseContext.SaveChangesAsync(); - - return Created(countrylocalnames); - } - - public async Task Put([FromRoute] string key, [FromBody] CountryLocalNames updatedCountryLocalNames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCountryLocalNames.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCountryLocalNames).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryLocalNamesExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCountryLocalNames); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta countrylocalnames) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - countrylocalnames.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CountryLocalNamesExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CountryLocalNamesExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.CountryLocalNames.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var countrylocalnames = await _databaseContext.CountryLocalNames.FindAsync(parsedKey); - if (countrylocalnames == null) - { - return NotFound(); - } - - _databaseContext.CountryLocalNames.Remove(countrylocalnames); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs deleted file mode 100644 index 30d5eaea89..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameChangedAppEvent.g.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateEvent - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.Events; - -/// -/// An application event raised when the name of a country changes. -/// -public partial class CountryNameChangedAppEvent : INoxApplicationEvent -{ - - /// - /// The identifier of the country. The Iso alpha 2 code. - /// - public CountryCode2? CountryId { get; set; } = null!; - - /// - /// The new name of the country. - /// - public Text? CountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs deleted file mode 100644 index 958ab8e47d..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CountryNameUpdatedEvent.g.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DomainEventGenerator::GenerateEvent - -using Nox.Abstractions; -using Nox.Types; - -namespace SampleWebApp.Domain; - -/// -/// Raised when the name of a country is changes. -/// -public partial class CountryNameUpdatedEvent : INoxDomainEvent -{ - - /// - /// The identifier of the country. The Iso Alpha2 code of the country. - /// - public CountryCode2? CountryId { get; set; } = null!; - - /// - /// The new name of the country. - /// - public Text? NewCountryName { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs deleted file mode 100644 index cb8ce6b2a0..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/CurrenciesController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class CurrenciesController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public CurrenciesController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Currencies); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Currencies.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Currency currency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Currencies.Add(currency); - - await _databaseContext.SaveChangesAsync(); - - return Created(currency); - } - - public async Task Put([FromRoute] string key, [FromBody] Currency updatedCurrency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedCurrency.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedCurrency).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CurrencyExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedCurrency); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta currency) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Currencies.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - currency.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!CurrencyExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool CurrencyExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Currencies.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var currency = await _databaseContext.Currencies.FindAsync(parsedKey); - if (currency == null) - { - return NotFound(); - } - - _databaseContext.Currencies.Remove(currency); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs deleted file mode 100644 index b8cd178735..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Currency.g.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// The list of currencies. -/// -public partial class Currency : AuditableEntityBase -{ - - /// - /// The currency's primary key / identifier (optional). - /// - public Text Id { get; set; } = null!; - - /// - /// The currency's name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// Currency is legal tender for ZeroOrMany Countries - /// - public List Countries { get; set; } = null!; - - public List CurrencyIsLegalTenderForCountry => Countries; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs deleted file mode 100644 index 61a67ada7e..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/EntityBase.g.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Generated - -#nullable enable - -using System; - -namespace SampleWebApp.Domain; - -/// -/// The base class for all domain entities. -/// -public partial class EntityBase -{ - /// - /// The state of the entity as at this date. - /// - public DateTime AsAt {get; set;} -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs deleted file mode 100644 index ecfc173c80..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Generator.g.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Generated - -#nullable enable - -// Found files -> -// - currency.entity.nox.yaml -// - elastic.monitoring.nox.yaml -// - sample.solution.nox.yaml -// - store.entity.nox.yaml -// - generator.nox.yaml -// SUCCESS. diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs deleted file mode 100644 index 75759492bb..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/GetCountriesByContinentQuery.g.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; -using System.Threading.Tasks; -using SampleWebApp.Domain; -using SampleWebApp.Application.DataTransferObjects; -using SampleWebApp.Infrastructure.Persistence; - -namespace SampleWebApp.Application; - -/// -/// Returns a list of countries for a given continent. -/// -public abstract partial class GetCountriesByContinentQuery -{ - - /// - /// Represents the DB context. - /// - protected SampleWebAppDbContext DbContext { get; set; } = null!; - - public GetCountriesByContinentQuery( - SampleWebAppDbContext dbContext - ) - { - DbContext = dbContext; - } - public abstract Task> ExecuteAsync(Text continentName); -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs deleted file mode 100644 index 7a1cd1084e..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/NoxServiceCollectionExtension.g.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.EntityFrameworkCore; -using Nox; -using Nox.DatabaseProvider.SqlServer; -using Nox.Types.EntityFramework.Abstractions; -using SampleWebApp.Infrastructure.Persistence; - -public static class NoxServiceCollectionExtension -{ - public static IServiceCollection AddNox(this IServiceCollection services) - { - services.AddNoxLib(); - services.AddSingleton>(); - services.AddSingleton(); - services.AddSingleton(); - services.AddDbContext(); - var tmpProvider = services.BuildServiceProvider(); - var dbContext = tmpProvider.GetRequiredService(); - dbContext.Database.EnsureCreated(); - return services; - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs deleted file mode 100644 index edc2647ca2..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/ODataConfiguration.g.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.OData; -using Microsoft.OData.ModelBuilder; -using SampleWebApp.Domain; -namespace SampleWebApp.Presentation.Api.OData; - -public partial class ODataConfiguration -{ - public static void Register(IServiceCollection services) - { - ODataModelBuilder builder = new ODataConventionModelBuilder(); - - builder.EntitySet("Countries"); - builder.EntitySet("Currencies"); - builder.EntitySet("Stores"); - builder.EntitySet("CountryLocalNames"); - - services.AddControllers() - .AddOData(options => options - .Select() - .Filter() - .OrderBy() - .Count() - .Expand() - .SkipToken() - .SetMaxTop(100) - .AddRouteComponents("api", builder.GetEdmModel()) - ); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs deleted file mode 100644 index c97ba5b5cb..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/SampleWebAppDbContext.g.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.EntityFrameworkCore; -using Nox.Solution; -using Nox.Types.EntityFramework.Abstractions; -using SampleWebApp.Domain; - -namespace SampleWebApp.Infrastructure.Persistence; - -public partial class SampleWebAppDbContext : DbContext -{ - private readonly NoxSolution _noxSolution; - private readonly INoxDatabaseProvider _dbProvider; - - public SampleWebAppDbContext( - DbContextOptions options, - NoxSolution noxSolution, - INoxDatabaseProvider databaseProvider - ) : base(options) - { - _noxSolution = noxSolution; - _dbProvider = databaseProvider; - } - - public DbSet Countries {get; set;} = null!; - - public DbSet Currencies {get; set;} = null!; - - public DbSet Stores {get; set;} = null!; - - public DbSet CountryLocalNames {get; set;} = null!; - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - base.OnConfiguring(optionsBuilder); - if (_noxSolution.Infrastructure is { Persistence.DatabaseServer: not null }) - { - _dbProvider.ConfigureDbContext(optionsBuilder, "SampleWebApp", _noxSolution.Infrastructure!.Persistence.DatabaseServer); - } - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - if (_noxSolution.Domain != null) - { - foreach (var entity in _noxSolution.Domain.Entities) - { - var type = Type.GetType("SampleWebApp.Domain." + entity.Name); - - if (type != null) - { - ((INoxDatabaseConfigurator)_dbProvider).ConfigureEntity(modelBuilder.Entity(type), entity); - } - } - - } - - base.OnModelCreating(modelBuilder); - } -} - diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs deleted file mode 100644 index fd77ec669a..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/Store.g.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System; -using System.Collections.Generic; - -namespace SampleWebApp.Domain; - -/// -/// Stores. -/// -public partial class Store : AuditableEntityBase -{ - - /// - /// Store Primary Key (optional). - /// - public Text Id { get; set; } = null!; - - /// - /// Store Name (required). - /// - public Text Name { get; set; } = null!; - - /// - /// Physical Money in the Physical Store (required). - /// - public Money PhysicalMoney { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs deleted file mode 100644 index 9bbdf7fc66..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/StoresController.g.cs +++ /dev/null @@ -1,140 +0,0 @@ -// Generated - -#nullable enable - -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Deltas; -using Microsoft.AspNetCore.OData.Query; -using Microsoft.AspNetCore.OData.Routing.Controllers; -using Microsoft.EntityFrameworkCore; -using SampleWebApp.Domain; -using SampleWebApp.Infrastructure.Persistence; -using Nox.Types; - -namespace SampleWebApp.Presentation.Api.OData; - -public class StoresController : ODataController -{ - SampleWebAppDbContext _databaseContext; - - public StoresController(SampleWebAppDbContext databaseContext) - { - _databaseContext = databaseContext; - } - - [EnableQuery] - public ActionResult> Get() - { - return Ok(_databaseContext.Stores); - } - - [EnableQuery] - public ActionResult Get([FromRoute] string key) - { - var parsedKey = Text.From(key); - var item = _databaseContext.Stores.SingleOrDefault(d => d.Id.Equals(parsedKey)); - - if (item == null) - { - return NotFound(); - } - return Ok(item); - } - - public async Task Post(Store store) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - _databaseContext.Stores.Add(store); - - await _databaseContext.SaveChangesAsync(); - - return Created(store); - } - - public async Task Put([FromRoute] string key, [FromBody] Store updatedStore) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - if (parsedKey != updatedStore.Id) - { - return BadRequest(); - } - _databaseContext.Entry(updatedStore).State = EntityState.Modified; - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!StoreExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(updatedStore); - } - - public async Task Patch([FromRoute] string key, [FromBody] Delta store) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - var parsedKey = Text.From(key); - var entity = await _databaseContext.Stores.FindAsync(parsedKey); - if (entity == null) - { - return NotFound(); - } - store.Patch(entity); - try - { - await _databaseContext.SaveChangesAsync(); - } - catch (DbUpdateConcurrencyException) - { - if (!StoreExists(key)) - { - return NotFound(); - } - else - { - throw; - } - } - return Updated(entity); - } - - private bool StoreExists(string key) - { - var parsedKey = Text.From(key); - return _databaseContext.Stores.Any(p => p.Id == parsedKey); - } - - public async Task Delete([FromRoute] string key) - { - var parsedKey = Text.From(key); - var store = await _databaseContext.Stores.FindAsync(parsedKey); - if (store == null) - { - return NotFound(); - } - - _databaseContext.Stores.Remove(store); - await _databaseContext.SaveChangesAsync(); - return NoContent(); - } -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs deleted file mode 100644 index 9b624fb469..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatistics.g.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Generated - -#nullable enable - -// Generated by DtoGenerator::GenerateDto - -using Nox.Abstractions; -using Nox.Types; -using System.Collections.Generic; - -namespace SampleWebApp.Application.DataTransferObjects; - - -/// -/// Instructs the service to collect updated population statistics. -/// -public partial class UpdatePopulationStatistics : IDynamicDto -{ - public CountryCode2? CountryCode { get; set; } = null!; -} diff --git a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs b/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs deleted file mode 100644 index a3cbbae4ea..0000000000 --- a/src/SampleWebApp/Generated/Nox.Generator/Nox.Generator.NoxCodeGenerator/UpdatePopulationStatisticsCommandHandlerBase.g.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Generated - -#nullable enable - -using Nox.Types; -using System.Collections.Generic; -using Nox.Abstractions; -using SampleWebApp.Domain; -using SampleWebApp.Application.DataTransferObjects; -using SampleWebApp.Infrastructure.Persistence; - -namespace SampleWebApp.Application; - -/// -/// Instructs the service to collect updated population statistics. -/// -public abstract partial class UpdatePopulationStatisticsCommandHandlerBase -{ - - /// - /// Represents the DB context. - /// - protected SampleWebAppDbContext DbContext { get; set; } = null!; - - /// - /// Represents the Nox messenger. - /// - protected INoxMessenger Messenger { get; set; } = null!; - - public UpdatePopulationStatisticsCommandHandlerBase( - SampleWebAppDbContext dbContext, - INoxMessenger messenger - ) - { - DbContext = dbContext; - Messenger = messenger; - } - - /// - /// Executes UpdatePopulationStatistics. - /// - public abstract Task ExecuteAsync(UpdatePopulationStatistics command); - - /// - /// Sends CountryNameUpdatedEvent. - /// - public async Task SendCountryNameUpdatedEventDomainEventAsync(CountryNameUpdatedEvent domainEvent) - { - await Messenger.SendMessageAsync(new string[] { "Mediator" }, domainEvent); - } -} diff --git a/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs b/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs index 0dc5cd59d3..9d8c10a7a7 100644 --- a/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs +++ b/tests/Nox.Generator.Tests/Database/Models/TestDatabaseWebAppDbContext.g.cs @@ -5,8 +5,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Nox.Solution; -using Nox.Types.EntityFramework.vNext; using System; +using Nox.Types.EntityFramework.Abstractions; using TestDatabaseWebApp.Domain; namespace TestDatabaseWebApp.Infrastructure.Persistence; diff --git a/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs b/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs index 7fcd9dc9c6..ed18665099 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteIntegrationTests.cs @@ -1,7 +1,7 @@ using FluentAssertions; using Nox.Types; -using NoxSourceGeneratorTests.DatabaseTests; using System.Linq; +using Nox.Generator.Tests.Database; using TestDatabaseWebApp.Domain; using Xunit; diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 7a2998941d..63d74b8653 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -1,11 +1,11 @@ -using Microsoft.Data.Sqlite; +using System; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; +using Nox.DatabaseProvider.Sqlite; using Nox.Solution; -using Nox.Types.EntityFramework.Sqlite; -using System; using TestDatabaseWebApp.Infrastructure.Persistence; -namespace NoxSourceGeneratorTests.DatabaseTests; +namespace Nox.Generator.Tests.Database; public abstract class SqliteTestBase : IDisposable { @@ -27,7 +27,7 @@ protected SqliteTestBase() private static TestDatabaseWebAppDbContext CreateDbContext(SqliteConnection connection) { - var databaseConfigurator = new SqliteDatabaseConfigurator(); + var databaseConfigurator = new SqliteDatabaseProvider(); var solution = new NoxSolutionBuilder() .UseYamlFile(_testSolutionFile) .Build(); diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index 1865008ee8..12cb3faefa 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -32,9 +32,8 @@ + - - From e8e641104d6dc509364b258a9a08e50bd2ff24d1 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 16:34:16 +0200 Subject: [PATCH 17/18] removed fluent validation from Generator --- src/Nox.Generator/Nox.Generator.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Nox.Generator/Nox.Generator.csproj b/src/Nox.Generator/Nox.Generator.csproj index c08a6bf211..84132407b5 100644 --- a/src/Nox.Generator/Nox.Generator.csproj +++ b/src/Nox.Generator/Nox.Generator.csproj @@ -26,7 +26,6 @@ - @@ -41,7 +40,6 @@ - From 5d0a4af899b96055351dfb7e50b9229050546837 Mon Sep 17 00:00:00 2001 From: Jan Schutte Date: Wed, 5 Jul 2023 16:45:01 +0200 Subject: [PATCH 18/18] renamed database provider projects to Nox.EntityFramework.* --- .../Nox.EntityFramework.Postgres.csproj} | 0 .../PostgresDatabaseProvider.cs | 2 +- .../PostgresTextDatabaseConfiguration.cs | 2 +- .../Nox.EntityFramework.SqlServer.csproj} | 0 .../SqlServerDatabaseProvider.cs | 2 +- .../SqlServerTextDatabaseConfigurator.cs | 2 +- .../Nox.EntityFramework.Sqlite.csproj} | 0 .../SqliteDatabaseProvider.cs | 2 +- src/Nox.Generator.sln | 6 +++--- .../Common/ServiceCollectionExtensionGenerator.cs | 4 ++-- src/Nox.Generator/Nox.Generator.csproj | 2 ++ src/Nox.Lib/Nox.Lib.csproj | 6 +++--- src/SampleWebApp/SampleWebApp.csproj | 2 +- tests/Nox.Generator.Tests/Database/SqliteTestBase.cs | 2 +- tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj | 2 +- 15 files changed, 18 insertions(+), 16 deletions(-) rename src/{Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj => Nox.EntityFramework.Postgres/Nox.EntityFramework.Postgres.csproj} (100%) rename src/{Nox.DatabaseProvider.Postgres => Nox.EntityFramework.Postgres}/PostgresDatabaseProvider.cs (98%) rename src/{Nox.DatabaseProvider.Postgres => Nox.EntityFramework.Postgres}/PostgresTextDatabaseConfiguration.cs (89%) rename src/{Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj => Nox.EntityFramework.SqlServer/Nox.EntityFramework.SqlServer.csproj} (100%) rename src/{Nox.DatabaseProvider.SqlServer => Nox.EntityFramework.SqlServer}/SqlServerDatabaseProvider.cs (98%) rename src/{Nox.DatabaseProvider.SqlServer => Nox.EntityFramework.SqlServer}/SqlServerTextDatabaseConfigurator.cs (86%) rename src/{Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj => Nox.EntityFramework.Sqlite/Nox.EntityFramework.Sqlite.csproj} (100%) rename src/{Nox.DatabaseProvider.Sqlite => Nox.EntityFramework.Sqlite}/SqliteDatabaseProvider.cs (96%) diff --git a/src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj b/src/Nox.EntityFramework.Postgres/Nox.EntityFramework.Postgres.csproj similarity index 100% rename from src/Nox.DatabaseProvider.Postgres/Nox.DatabaseProvider.Postgres.csproj rename to src/Nox.EntityFramework.Postgres/Nox.EntityFramework.Postgres.csproj diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs b/src/Nox.EntityFramework.Postgres/PostgresDatabaseProvider.cs similarity index 98% rename from src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs rename to src/Nox.EntityFramework.Postgres/PostgresDatabaseProvider.cs index 3a9a8be7d7..ed557e9cdf 100644 --- a/src/Nox.DatabaseProvider.Postgres/PostgresDatabaseProvider.cs +++ b/src/Nox.EntityFramework.Postgres/PostgresDatabaseProvider.cs @@ -5,7 +5,7 @@ using Nox.Types.EntityFramework.Configurators; using Npgsql; -namespace Nox.DatabaseProvider.Postgres; +namespace Nox.EntityFramework.Postgres; public class PostgresDatabaseProvider: NoxDatabaseConfigurator, INoxDatabaseProvider { diff --git a/src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs b/src/Nox.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs similarity index 89% rename from src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs rename to src/Nox.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs index 682c5cacde..460e4ea193 100644 --- a/src/Nox.DatabaseProvider.Postgres/PostgresTextDatabaseConfiguration.cs +++ b/src/Nox.EntityFramework.Postgres/PostgresTextDatabaseConfiguration.cs @@ -1,7 +1,7 @@ using Nox.Types; using Nox.Types.EntityFramework.Configurators; -namespace Nox.DatabaseProvider.Postgres; +namespace Nox.EntityFramework.Postgres; public class PostgresTextDatabaseConfiguration : TextDatabaseConfigurator { diff --git a/src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj b/src/Nox.EntityFramework.SqlServer/Nox.EntityFramework.SqlServer.csproj similarity index 100% rename from src/Nox.DatabaseProvider.SqlServer/Nox.DatabaseProvider.SqlServer.csproj rename to src/Nox.EntityFramework.SqlServer/Nox.EntityFramework.SqlServer.csproj diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs b/src/Nox.EntityFramework.SqlServer/SqlServerDatabaseProvider.cs similarity index 98% rename from src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs rename to src/Nox.EntityFramework.SqlServer/SqlServerDatabaseProvider.cs index 38d24e95f0..f270c4b1c4 100644 --- a/src/Nox.DatabaseProvider.SqlServer/SqlServerDatabaseProvider.cs +++ b/src/Nox.EntityFramework.SqlServer/SqlServerDatabaseProvider.cs @@ -5,7 +5,7 @@ using Nox.Types.EntityFramework.Abstractions; using Nox.Types.EntityFramework.Configurators; -namespace Nox.DatabaseProvider.SqlServer; +namespace Nox.EntityFramework.SqlServer; public class SqlServerDatabaseProvider: NoxDatabaseConfigurator, INoxDatabaseProvider { diff --git a/src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs b/src/Nox.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs similarity index 86% rename from src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs rename to src/Nox.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs index 7280a47761..106cda2429 100644 --- a/src/Nox.DatabaseProvider.SqlServer/SqlServerTextDatabaseConfigurator.cs +++ b/src/Nox.EntityFramework.SqlServer/SqlServerTextDatabaseConfigurator.cs @@ -1,7 +1,7 @@ using Nox.Types; using Nox.Types.EntityFramework.Configurators; -namespace Nox.DatabaseProvider.SqlServer; +namespace Nox.EntityFramework.SqlServer; public class SqlServerTextDatabaseConfigurator : TextDatabaseConfigurator { diff --git a/src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj b/src/Nox.EntityFramework.Sqlite/Nox.EntityFramework.Sqlite.csproj similarity index 100% rename from src/Nox.DatabaseProvider.Sqlite/Nox.DatabaseProvider.Sqlite.csproj rename to src/Nox.EntityFramework.Sqlite/Nox.EntityFramework.Sqlite.csproj diff --git a/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs b/src/Nox.EntityFramework.Sqlite/SqliteDatabaseProvider.cs similarity index 96% rename from src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs rename to src/Nox.EntityFramework.Sqlite/SqliteDatabaseProvider.cs index a83d9fd064..542d77ae53 100644 --- a/src/Nox.DatabaseProvider.Sqlite/SqliteDatabaseProvider.cs +++ b/src/Nox.EntityFramework.Sqlite/SqliteDatabaseProvider.cs @@ -4,7 +4,7 @@ using Nox.Types.EntityFramework.Abstractions; using Nox.Types.EntityFramework.Configurators; -namespace Nox.DatabaseProvider.Sqlite; +namespace Nox.EntityFramework.Sqlite; public sealed class SqliteDatabaseProvider : NoxDatabaseConfigurator, INoxDatabaseProvider { diff --git a/src/Nox.Generator.sln b/src/Nox.Generator.sln index be8de462d3..83335edc64 100644 --- a/src/Nox.Generator.sln +++ b/src/Nox.Generator.sln @@ -49,11 +49,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.Types.Tests", "..\tests EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DatabaseProviders", "DatabaseProviders", "{873BFCC4-435D-44D7-8287-1FB1574B2319}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Postgres", "Nox.DatabaseProvider.Postgres\Nox.DatabaseProvider.Postgres.csproj", "{55D717E8-6043-487C-83A9-8AE2E92086D7}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.EntityFramework.Postgres", "Nox.EntityFramework.Postgres\Nox.EntityFramework.Postgres.csproj", "{55D717E8-6043-487C-83A9-8AE2E92086D7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.SqlServer", "Nox.DatabaseProvider.SqlServer\Nox.DatabaseProvider.SqlServer.csproj", "{A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.EntityFramework.SqlServer", "Nox.EntityFramework.SqlServer\Nox.EntityFramework.SqlServer.csproj", "{A851D896-AC63-4DC0-98FC-9E1EEA5DACE5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.DatabaseProvider.Sqlite", "Nox.DatabaseProvider.Sqlite\Nox.DatabaseProvider.Sqlite.csproj", "{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nox.EntityFramework.Sqlite", "Nox.EntityFramework.Sqlite\Nox.EntityFramework.Sqlite.csproj", "{049C94B7-EC09-4511-B6BC-21DE2C9C54E1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs index 85a31f4aed..4ff36630a8 100644 --- a/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs +++ b/src/Nox.Generator/Common/ServiceCollectionExtensionGenerator.cs @@ -21,11 +21,11 @@ public static void Generate(SourceProductionContext context, NoxSolution solutio switch (dbServer.Provider) { case DatabaseServerProvider.SqlServer: - usings.Add("using Nox.DatabaseProvider.SqlServer;"); + usings.Add("using Nox.EntityFramework.SqlServer;"); dbProvider = "SqlServerDatabaseProvider"; break; case DatabaseServerProvider.Postgres: - usings.Add("using Nox.DatabaseProvider.Postgres;"); + usings.Add("using Nox.EntityFramework.Postgres;"); dbProvider = "PostgresDatabaseProvider"; break; } diff --git a/src/Nox.Generator/Nox.Generator.csproj b/src/Nox.Generator/Nox.Generator.csproj index 84132407b5..086d657e81 100644 --- a/src/Nox.Generator/Nox.Generator.csproj +++ b/src/Nox.Generator/Nox.Generator.csproj @@ -26,6 +26,7 @@ + @@ -40,6 +41,7 @@ + diff --git a/src/Nox.Lib/Nox.Lib.csproj b/src/Nox.Lib/Nox.Lib.csproj index b9dac80026..2ca1adbfee 100644 --- a/src/Nox.Lib/Nox.Lib.csproj +++ b/src/Nox.Lib/Nox.Lib.csproj @@ -36,9 +36,9 @@ - - - + + + diff --git a/src/SampleWebApp/SampleWebApp.csproj b/src/SampleWebApp/SampleWebApp.csproj index 01fdb16c0d..1417f416dd 100644 --- a/src/SampleWebApp/SampleWebApp.csproj +++ b/src/SampleWebApp/SampleWebApp.csproj @@ -34,7 +34,7 @@ - + diff --git a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs index 63d74b8653..ec43301979 100644 --- a/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs +++ b/tests/Nox.Generator.Tests/Database/SqliteTestBase.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -using Nox.DatabaseProvider.Sqlite; +using Nox.EntityFramework.Sqlite; using Nox.Solution; using TestDatabaseWebApp.Infrastructure.Persistence; diff --git a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj index 12cb3faefa..183863dc18 100644 --- a/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj +++ b/tests/Nox.Generator.Tests/Nox.Generator.Tests.csproj @@ -32,7 +32,7 @@ - +