From 2bb0a31b2d81cda1b58a32a50b43be57dbffe2a1 Mon Sep 17 00:00:00 2001 From: 丁松杰 <377973147@qq.com> Date: Thu, 9 Jan 2020 12:29:46 +0800 Subject: [PATCH] 添加 产品 微服务 数据 --- Pole.sln | 6 +++--- samples/apis/Order.Api/Order.Api.csproj | 7 +++++++ samples/apis/Product.Api/Domain/ProductAggregate/IProductRepository.cs | 13 +++++++++++++ samples/apis/Product.Api/Domain/ProductAggregate/Product.cs | 15 +++++++++++++++ samples/apis/Product.Api/Domain/ProductTypeAggregate/ProductType.cs | 13 +++++++++++++ samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductEntityTypeConfiguration.cs | 26 ++++++++++++++++++++++++++ samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductTypeEntityTypeConfiguration.cs | 25 +++++++++++++++++++++++++ samples/apis/Product.Api/Infrastructure/ProductDbContext.cs | 30 ++++++++++++++++++++++++++++++ samples/apis/Product.Api/Migrations/20200108090435_init.Designer.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ samples/apis/Product.Api/Migrations/20200108090435_init.cs | 35 +++++++++++++++++++++++++++++++++++ samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.Designer.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ samples/apis/Product.Api/Migrations/ProductDbContextModelSnapshot.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ samples/apis/Product.Api/Product.Api.csproj | 21 ++++++++++++++++++++- samples/apis/Product.Api/ProductDbContextDesignFactory.cs | 30 ++++++++++++++++++++++++++++++ samples/apis/Product.Api/Startup.cs | 14 ++++++++++++++ samples/apis/Product.Api/appsettings.Development.json | 3 +++ samples/proto/service/Order/order.proto | 28 ++++++++++++++++++++++++++++ samples/proto/service/Product/product.proto | 24 ++++++++++++++++++++++++ samples/proto/service/Product/productType.proto | 21 +++++++++++++++++++++ src/Pole.Core/MediatR/IServiceCollectionExtensions.cs | 24 ++++++++++++++++++++++++ src/Pole.Core/Pole.Core.csproj | 4 ++++ src/Pole.Domain.EntityframeworkCore/MediatR/NoMediator.cs | 32 ++++++++++++++++++++++++++++++++ src/Pole.Domain/Entity/AggregateRoot.cs | 9 --------- src/Pole.Domain/Entity/IAggregateRoot.cs | 9 +++++++++ src/Pole.Domain/IRepository.cs | 2 +- src/Pole.Domain/Pole.Domain.csproj | 6 ++++++ src/Pole.Domain/ServiceCollectionExtensions.cs | 17 +++++++++++++++++ 28 files changed, 600 insertions(+), 14 deletions(-) create mode 100644 samples/apis/Product.Api/Domain/ProductAggregate/IProductRepository.cs create mode 100644 samples/apis/Product.Api/Domain/ProductAggregate/Product.cs create mode 100644 samples/apis/Product.Api/Domain/ProductTypeAggregate/ProductType.cs create mode 100644 samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductEntityTypeConfiguration.cs create mode 100644 samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductTypeEntityTypeConfiguration.cs create mode 100644 samples/apis/Product.Api/Infrastructure/ProductDbContext.cs create mode 100644 samples/apis/Product.Api/Migrations/20200108090435_init.Designer.cs create mode 100644 samples/apis/Product.Api/Migrations/20200108090435_init.cs create mode 100644 samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.Designer.cs create mode 100644 samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.cs create mode 100644 samples/apis/Product.Api/Migrations/ProductDbContextModelSnapshot.cs create mode 100644 samples/apis/Product.Api/ProductDbContextDesignFactory.cs create mode 100644 samples/proto/service/Order/order.proto create mode 100644 samples/proto/service/Product/product.proto create mode 100644 samples/proto/service/Product/productType.proto create mode 100644 src/Pole.Core/MediatR/IServiceCollectionExtensions.cs create mode 100644 src/Pole.Domain.EntityframeworkCore/MediatR/NoMediator.cs delete mode 100644 src/Pole.Domain/Entity/AggregateRoot.cs create mode 100644 src/Pole.Domain/Entity/IAggregateRoot.cs create mode 100644 src/Pole.Domain/ServiceCollectionExtensions.cs diff --git a/Pole.sln b/Pole.sln index 58e8af3..8808d7d 100644 --- a/Pole.sln +++ b/Pole.sln @@ -35,11 +35,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pole.ReliableMessage.Storag EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "webs", "webs", "{452B9D9E-881E-4E0E-A90B-98F2253F20F1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Order.Api", "samples\apis\Order.Api\Order.Api.csproj", "{098DF771-6DC6-45D4-ABFA-FF84E8F7750B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Order.Api", "samples\apis\Order.Api\Order.Api.csproj", "{098DF771-6DC6-45D4-ABFA-FF84E8F7750B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Product.Api", "samples\apis\Product.Api\Product.Api.csproj", "{125B1E4B-B1C1-4F85-9C6A-38815960E654}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Product.Api", "samples\apis\Product.Api\Product.Api.csproj", "{125B1E4B-B1C1-4F85-9C6A-38815960E654}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backet.Api", "samples\apis\Backet.Api\Backet.Api.csproj", "{C961F25C-1C11-4855-84E4-ADABE96451E7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Backet.Api", "samples\apis\Backet.Api\Backet.Api.csproj", "{C961F25C-1C11-4855-84E4-ADABE96451E7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/samples/apis/Order.Api/Order.Api.csproj b/samples/apis/Order.Api/Order.Api.csproj index 2a452c7..cb7a4e1 100644 --- a/samples/apis/Order.Api/Order.Api.csproj +++ b/samples/apis/Order.Api/Order.Api.csproj @@ -5,6 +5,13 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/samples/apis/Product.Api/Domain/ProductAggregate/IProductRepository.cs b/samples/apis/Product.Api/Domain/ProductAggregate/IProductRepository.cs new file mode 100644 index 0000000..15a8cca --- /dev/null +++ b/samples/apis/Product.Api/Domain/ProductAggregate/IProductRepository.cs @@ -0,0 +1,13 @@ +using Pole.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Domain.ProductAggregate +{ + public interface IProductRepository : IRepository + { + + } +} diff --git a/samples/apis/Product.Api/Domain/ProductAggregate/Product.cs b/samples/apis/Product.Api/Domain/ProductAggregate/Product.cs new file mode 100644 index 0000000..9be47c4 --- /dev/null +++ b/samples/apis/Product.Api/Domain/ProductAggregate/Product.cs @@ -0,0 +1,15 @@ +using Pole.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Domain.ProductAggregate +{ + public class Product : Entity, IAggregateRoot + { + public string Name { get; set; } + public long Price { get; set; } + public string ProductId { get; set; } + } +} diff --git a/samples/apis/Product.Api/Domain/ProductTypeAggregate/ProductType.cs b/samples/apis/Product.Api/Domain/ProductTypeAggregate/ProductType.cs new file mode 100644 index 0000000..6b382a1 --- /dev/null +++ b/samples/apis/Product.Api/Domain/ProductTypeAggregate/ProductType.cs @@ -0,0 +1,13 @@ +using Pole.Domain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Domain.ProductTypeAggregate +{ + public class ProductType : Entity, IAggregateRoot + { + public string Name { get; set; } + } +} diff --git a/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductEntityTypeConfiguration.cs b/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductEntityTypeConfiguration.cs new file mode 100644 index 0000000..6e7c125 --- /dev/null +++ b/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductEntityTypeConfiguration.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Infrastructure.EntityConfigurations +{ + public class ProductEntityTypeEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(Product)); + + builder.Property(m => m.Id).HasMaxLength(32); + builder.Property(m => m.Name).HasMaxLength(256).IsRequired(); + builder.Property(m => m.ProductId).HasMaxLength(32).IsRequired(); + + builder.Ignore(m => m.DomainEvents); + + builder.HasIndex(m => m.ProductId); + builder.HasKey(m => m.Id); + } + } +} diff --git a/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductTypeEntityTypeConfiguration.cs b/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductTypeEntityTypeConfiguration.cs new file mode 100644 index 0000000..b7ad4e2 --- /dev/null +++ b/samples/apis/Product.Api/Infrastructure/EntityConfigurations/ProductTypeEntityTypeConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Product.Api.Domain.ProductTypeAggregate; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Infrastructure.EntityConfigurations +{ + public class ProductTypeEntityTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable(nameof(ProductType)); + + builder.Property(m => m.Id).HasMaxLength(32); + builder.Property(m => m.Name).HasMaxLength(256).IsRequired(); + + builder.Ignore(m => m.DomainEvents); + + builder.HasKey(m => m.Id); + } + } +} diff --git a/samples/apis/Product.Api/Infrastructure/ProductDbContext.cs b/samples/apis/Product.Api/Infrastructure/ProductDbContext.cs new file mode 100644 index 0000000..826db0b --- /dev/null +++ b/samples/apis/Product.Api/Infrastructure/ProductDbContext.cs @@ -0,0 +1,30 @@ +using MediatR; +using Microsoft.EntityFrameworkCore; +using Pole.EntityframeworkCore; +using Product.Api.Infrastructure.EntityConfigurations; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api.Infrastructure +{ + public class ProductDbContext : DbContextBase + { + public ProductDbContext(DbContextOptions options, IMediator mediator) : base(options, mediator) + { + + } + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + + builder.ApplyConfiguration(new ProductEntityTypeEntityTypeConfiguration()); + builder.ApplyConfiguration(new ProductTypeEntityTypeConfiguration()); + + //builder.ApplyConfiguration(new ThinkNestDirectSalesManagerEntityTypeConfiguration()); + //builder.ApplyConfiguration(new ThinkNestInDirectSalesManagerEntityTypeConfiguration()); + + } + } +} diff --git a/samples/apis/Product.Api/Migrations/20200108090435_init.Designer.cs b/samples/apis/Product.Api/Migrations/20200108090435_init.Designer.cs new file mode 100644 index 0000000..2839322 --- /dev/null +++ b/samples/apis/Product.Api/Migrations/20200108090435_init.Designer.cs @@ -0,0 +1,49 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Product.Api.Infrastructure; + +namespace Product.Api.Migrations +{ + [DbContext(typeof(ProductDbContext))] + [Migration("20200108090435_init")] + partial class init + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "3.1.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Product.Api.Domain.ProductAggregate.Product", b => + { + b.Property("Id") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.Property("Name") + .HasColumnType("character varying(256)") + .HasMaxLength(256); + + b.Property("Price") + .HasColumnType("bigint"); + + b.Property("ProductId") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Product"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/apis/Product.Api/Migrations/20200108090435_init.cs b/samples/apis/Product.Api/Migrations/20200108090435_init.cs new file mode 100644 index 0000000..13f19f7 --- /dev/null +++ b/samples/apis/Product.Api/Migrations/20200108090435_init.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Product.Api.Migrations +{ + public partial class init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Product", + columns: table => new + { + Id = table.Column(maxLength: 32, nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + Price = table.Column(nullable: false), + ProductId = table.Column(maxLength: 32, nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Product", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Product_ProductId", + table: "Product", + column: "ProductId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Product"); + } + } +} diff --git a/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.Designer.cs b/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.Designer.cs new file mode 100644 index 0000000..66db2dd --- /dev/null +++ b/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.Designer.cs @@ -0,0 +1,51 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Product.Api.Infrastructure; + +namespace Product.Api.Migrations +{ + [DbContext(typeof(ProductDbContext))] + [Migration("20200108092455_Modify_Product_ProductId")] + partial class Modify_Product_ProductId + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "3.1.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Product.Api.Domain.ProductAggregate.Product", b => + { + b.Property("Id") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.Property("Name") + .IsRequired() + .HasColumnType("character varying(256)") + .HasMaxLength(256); + + b.Property("Price") + .HasColumnType("bigint"); + + b.Property("ProductId") + .IsRequired() + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Product"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.cs b/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.cs new file mode 100644 index 0000000..39fa3af --- /dev/null +++ b/samples/apis/Product.Api/Migrations/20200108092455_Modify_Product_ProductId.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Product.Api.Migrations +{ + public partial class Modify_Product_ProductId : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ProductId", + table: "Product", + maxLength: 32, + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(32)", + oldMaxLength: 32, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Product", + maxLength: 256, + nullable: false, + oldClrType: typeof(string), + oldType: "character varying(256)", + oldMaxLength: 256, + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ProductId", + table: "Product", + type: "character varying(32)", + maxLength: 32, + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 32); + + migrationBuilder.AlterColumn( + name: "Name", + table: "Product", + type: "character varying(256)", + maxLength: 256, + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 256); + } + } +} diff --git a/samples/apis/Product.Api/Migrations/ProductDbContextModelSnapshot.cs b/samples/apis/Product.Api/Migrations/ProductDbContextModelSnapshot.cs new file mode 100644 index 0000000..23229f6 --- /dev/null +++ b/samples/apis/Product.Api/Migrations/ProductDbContextModelSnapshot.cs @@ -0,0 +1,49 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Product.Api.Infrastructure; + +namespace Product.Api.Migrations +{ + [DbContext(typeof(ProductDbContext))] + partial class ProductDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + .HasAnnotation("ProductVersion", "3.1.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Product.Api.Domain.ProductAggregate.Product", b => + { + b.Property("Id") + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.Property("Name") + .IsRequired() + .HasColumnType("character varying(256)") + .HasMaxLength(256); + + b.Property("Price") + .HasColumnType("bigint"); + + b.Property("ProductId") + .IsRequired() + .HasColumnType("character varying(32)") + .HasMaxLength(32); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Product"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/samples/apis/Product.Api/Product.Api.csproj b/samples/apis/Product.Api/Product.Api.csproj index 92605c5..47305a2 100644 --- a/samples/apis/Product.Api/Product.Api.csproj +++ b/samples/apis/Product.Api/Product.Api.csproj @@ -1,7 +1,26 @@ - + netcoreapp3.1 + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/samples/apis/Product.Api/ProductDbContextDesignFactory.cs b/samples/apis/Product.Api/ProductDbContextDesignFactory.cs new file mode 100644 index 0000000..038eadb --- /dev/null +++ b/samples/apis/Product.Api/ProductDbContextDesignFactory.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; +using Pole.Domain.EntityframeworkCore.MediatR; +using Product.Api.Infrastructure; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace Product.Api +{ + public class ProductDbContextDesignFactory : IDesignTimeDbContextFactory + { + public ProductDbContext CreateDbContext(string[] args) + { + IConfigurationRoot configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.Development.json") + .Build(); + var optionsBuilder = new DbContextOptionsBuilder() + .UseNpgsql(configuration["postgres:main"]); + + return new ProductDbContext(optionsBuilder.Options, new NoMediator()); + } + + + } +} diff --git a/samples/apis/Product.Api/Startup.cs b/samples/apis/Product.Api/Startup.cs index 80cb1f7..6743c0d 100644 --- a/samples/apis/Product.Api/Startup.cs +++ b/samples/apis/Product.Api/Startup.cs @@ -5,17 +5,31 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Product.Api.Infrastructure; namespace Product.Api { public class Startup { + private IConfiguration Configuration { get; } + private IWebHostEnvironment Environment { get; } + public Startup(IConfiguration configuration, IWebHostEnvironment env) + { + this.Configuration = configuration; + this.Environment = env; + } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddDbContext(options => + options.UseNpgsql(Configuration["postgres:main"])); + + services.AddPoleDomain(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/samples/apis/Product.Api/appsettings.Development.json b/samples/apis/Product.Api/appsettings.Development.json index 8983e0f..b72e5cd 100644 --- a/samples/apis/Product.Api/appsettings.Development.json +++ b/samples/apis/Product.Api/appsettings.Development.json @@ -5,5 +5,8 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } + }, + "postgres": { + "main": "Server=192.168.0.248;Port=5432;Username=postgres;Password=comteck2020!@#;Database=Pole_samples_Product;Enlist=True;Timeout=0;Command Timeout=600;Pooling=false;MinPoolSize=20;MaxPoolSize=500;" } } diff --git a/samples/proto/service/Order/order.proto b/samples/proto/service/Order/order.proto new file mode 100644 index 0000000..f90639c --- /dev/null +++ b/samples/proto/service/Order/order.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + + +package newArchitectureLab.apps.order; + + +service Order { + + rpc GetById (GetByIdRequest) returns (GetByIdResponse); +} + + +message GetByIdRequest { + string id = 1; +} + + +message GetByIdResponse { + string id = 1; + double totalprice = 2; + repeated Product products = 3 ; + + message Product { + string id = 1 ; + string name = 2 ; + double price = 3 ; + } +} \ No newline at end of file diff --git a/samples/proto/service/Product/product.proto b/samples/proto/service/Product/product.proto new file mode 100644 index 0000000..e9ccd7b --- /dev/null +++ b/samples/proto/service/Product/product.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + + +package newArchitectureLab.apps.product; + +// The product service definition. +service Product { + + rpc GetById (GetByIdRequest) returns (GetByIdResponse); +} + + +message GetByIdRequest { + string Id = 1; +} + + +message GetByIdResponse { + string id = 1; + string name = 2; + double price = 3; + int64 stock = 4; + string productTypeId = 5; +} \ No newline at end of file diff --git a/samples/proto/service/Product/productType.proto b/samples/proto/service/Product/productType.proto new file mode 100644 index 0000000..1c9ddab --- /dev/null +++ b/samples/proto/service/Product/productType.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + + +package newArchitectureLab.apps.product; + +// The greeting service definition. +service ProductType { + // Sends a greeting + rpc GetById (GetProductTypeRequest) returns (GetProductTypeResponse); +} + +// The request message containing the user's name. +message GetProductTypeRequest { + string id = 1; +} + +// The response message containing the greetings. +message GetProductTypeResponse { + string id = 1; + string name = 2; +} \ No newline at end of file diff --git a/src/Pole.Core/MediatR/IServiceCollectionExtensions.cs b/src/Pole.Core/MediatR/IServiceCollectionExtensions.cs new file mode 100644 index 0000000..6ef6599 --- /dev/null +++ b/src/Pole.Core/MediatR/IServiceCollectionExtensions.cs @@ -0,0 +1,24 @@ +using MediatR; +using MediatR.Registration; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class IServiceCollectionExtensions + { + public static IServiceCollection AddMediatR(this IServiceCollection services) + { + var serviceConfig = new MediatRServiceConfiguration(); + + ServiceRegistrar.AddRequiredServices(services, serviceConfig); + + ServiceRegistrar.AddMediatRClasses(services, new Assembly[0]); + + return services; + } + } +} diff --git a/src/Pole.Core/Pole.Core.csproj b/src/Pole.Core/Pole.Core.csproj index 9f5c4f4..a965846 100644 --- a/src/Pole.Core/Pole.Core.csproj +++ b/src/Pole.Core/Pole.Core.csproj @@ -4,4 +4,8 @@ netstandard2.0 + + + + diff --git a/src/Pole.Domain.EntityframeworkCore/MediatR/NoMediator.cs b/src/Pole.Domain.EntityframeworkCore/MediatR/NoMediator.cs new file mode 100644 index 0000000..e475944 --- /dev/null +++ b/src/Pole.Domain.EntityframeworkCore/MediatR/NoMediator.cs @@ -0,0 +1,32 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Pole.Domain.EntityframeworkCore.MediatR +{ + public class NoMediator : IMediator + { + public Task Publish(object notification, CancellationToken cancellationToken = default) + { + return Task.CompletedTask; + } + + public Task Publish(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification + { + return Task.CompletedTask; + } + + public Task Send(IRequest request, CancellationToken cancellationToken = default) + { + return Task.FromResult(default(TResponse)); + } + + public Task Send(object request, CancellationToken cancellationToken = default) + { + return Task.FromResult(default(object)); + } + } +} diff --git a/src/Pole.Domain/Entity/AggregateRoot.cs b/src/Pole.Domain/Entity/AggregateRoot.cs deleted file mode 100644 index 8a87e32..0000000 --- a/src/Pole.Domain/Entity/AggregateRoot.cs +++ /dev/null @@ -1,9 +0,0 @@ -using MediatR; -using System; -using System.Collections.Generic; -using System.Text; - -namespace Pole.Domain -{ - public interface AggregateRoot { } -} diff --git a/src/Pole.Domain/Entity/IAggregateRoot.cs b/src/Pole.Domain/Entity/IAggregateRoot.cs new file mode 100644 index 0000000..50449a6 --- /dev/null +++ b/src/Pole.Domain/Entity/IAggregateRoot.cs @@ -0,0 +1,9 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Pole.Domain +{ + public interface IAggregateRoot { } +} diff --git a/src/Pole.Domain/IRepository.cs b/src/Pole.Domain/IRepository.cs index 92d7e9a..5b7ae93 100644 --- a/src/Pole.Domain/IRepository.cs +++ b/src/Pole.Domain/IRepository.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Pole.Domain { - public interface IRepository : IRepository where T : AggregateRoot + public interface IRepository : IRepository where T : IAggregateRoot { void Update(T entity); void Delete(T entity); diff --git a/src/Pole.Domain/Pole.Domain.csproj b/src/Pole.Domain/Pole.Domain.csproj index f4aadb7..794f936 100644 --- a/src/Pole.Domain/Pole.Domain.csproj +++ b/src/Pole.Domain/Pole.Domain.csproj @@ -6,6 +6,12 @@ + + + + + + diff --git a/src/Pole.Domain/ServiceCollectionExtensions.cs b/src/Pole.Domain/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..0f3bca3 --- /dev/null +++ b/src/Pole.Domain/ServiceCollectionExtensions.cs @@ -0,0 +1,17 @@ +using MediatR; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddPoleDomain(this IServiceCollection service) + { + service.AddMediatR(); + return service; + } + } +} -- libgit2 0.25.0