Commit 2bb0a31b by 丁松杰

添加 产品 微服务 数据

parent 12b51940
Showing with 595 additions and 6 deletions
......@@ -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
......
......@@ -5,6 +5,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Pole.ReliableMessage.Masstransit\Pole.ReliableMessage.Masstransit.csproj" />
<ProjectReference Include="..\..\..\src\Pole.ReliableMessage.Storage.Mongodb\Pole.ReliableMessage.Storage.Mongodb.csproj" />
<ProjectReference Include="..\..\..\src\Pole.ReliableMessage\Pole.ReliableMessage.csproj" />
......
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<Product>
{
}
}
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; }
}
}
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; }
}
}
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<Product.Api.Domain.ProductAggregate.Product>
{
public void Configure(EntityTypeBuilder<Product.Api.Domain.ProductAggregate.Product> 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);
}
}
}
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<ProductType>
{
public void Configure(EntityTypeBuilder<ProductType> 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);
}
}
}
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());
}
}
}
// <auto-generated />
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<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("Name")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<string>("ProductId")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("Product");
});
#pragma warning restore 612, 618
}
}
}
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<string>(maxLength: 32, nullable: false),
Name = table.Column<string>(maxLength: 256, nullable: true),
Price = table.Column<long>(nullable: false),
ProductId = table.Column<string>(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");
}
}
}
// <auto-generated />
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<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("character varying(256)")
.HasMaxLength(256);
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<string>("ProductId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("Product");
});
#pragma warning restore 612, 618
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace Product.Api.Migrations
{
public partial class Modify_Product_ProductId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "ProductId",
table: "Product",
maxLength: 32,
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(32)",
oldMaxLength: 32,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
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<string>(
name: "ProductId",
table: "Product",
type: "character varying(32)",
maxLength: 32,
nullable: true,
oldClrType: typeof(string),
oldMaxLength: 32);
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "Product",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldMaxLength: 256);
}
}
}
// <auto-generated />
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<string>("Id")
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("character varying(256)")
.HasMaxLength(256);
b.Property<long>("Price")
.HasColumnType("bigint");
b.Property<string>("ProductId")
.IsRequired()
.HasColumnType("character varying(32)")
.HasMaxLength(32);
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("Product");
});
#pragma warning restore 612, 618
}
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Pole.Domain.EntityframeworkCore\Pole.Domain.EntityframeworkCore.csproj" />
<ProjectReference Include="..\..\..\src\Pole.Domain\Pole.Domain.csproj" />
</ItemGroup>
</Project>
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<ProductDbContext>
{
public ProductDbContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.Development.json")
.Build();
var optionsBuilder = new DbContextOptionsBuilder<ProductDbContext>()
.UseNpgsql(configuration["postgres:main"]);
return new ProductDbContext(optionsBuilder.Options, new NoMediator());
}
}
}
......@@ -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<ProductDbContext>(options =>
options.UseNpgsql(Configuration["postgres:main"]));
services.AddPoleDomain();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
......@@ -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;"
}
}
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
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
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
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;
}
}
}
......@@ -4,4 +4,8 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
</ItemGroup>
</Project>
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>(TNotification notification, CancellationToken cancellationToken = default) where TNotification : INotification
{
return Task.CompletedTask;
}
public Task<TResponse> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default)
{
return Task.FromResult(default(TResponse));
}
public Task<object> Send(object request, CancellationToken cancellationToken = default)
{
return Task.FromResult(default(object));
}
}
}
......@@ -5,5 +5,5 @@ using System.Text;
namespace Pole.Domain
{
public interface AggregateRoot { }
public interface IAggregateRoot { }
}
......@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Pole.Domain
{
public interface IRepository<T> : IRepository where T : AggregateRoot
public interface IRepository<T> : IRepository where T : IAggregateRoot
{
void Update(T entity);
void Delete(T entity);
......
......@@ -6,6 +6,12 @@
<ItemGroup>
<PackageReference Include="MediatR" Version="8.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Pole.Core\Pole.Core.csproj" />
</ItemGroup>
</Project>
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;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment