+ Request ID: @Model.RequestId
+
+ Swapping to the Development environment displays detailed information about the error that occurred. +
++ The Development environment shouldn't be enabled for deployed applications. + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development + and restarting the app. +
diff --git a/CQRS_Simple.API/Pages/Error.cshtml.cs b/CQRS_Simple.API/Pages/Error.cshtml.cs new file mode 100644 index 0000000..e3f3ef7 --- /dev/null +++ b/CQRS_Simple.API/Pages/Error.cshtml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.Logging; + +namespace CQRS_Simple.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public class ErrorModel : PageModel + { + private readonly ILogger(}(2Kf7BCZ>Vc;V>ccbk2~NGaf6wGQH@W9&?Zt3v(h*P4xDrN>ex7+jH*+Qg z%^jH$&+*!v{sQ!xkWN4+>|b}qGvEd6ANzgqoVy5Qfws}ef2QqF{iiR5{pT}PS&yjo z>lron#va-p=v;m>WB+XVz|o;UJFdjo5_!RRD|6W{4}A2a#bZv)gS_`b|KsSH)Sd_JIr%<%n06TX&t{&!H#{)?4W9hlJ`R1>FyugOh3=D_{einr zu(Wf`qTkvED+gEULO0I*Hs%f;&=`=X4;N8Ovf28x$A*11`dmfy2=$+PNqX>XcG`h% zJY&A6@&)*WT^rC(Caj}2+|X|6cICm5h0OK0cGB_!wEKFZJU)OQ+TZ1q2bTx9hxnq& z$9ee|f9|0M^)#E&Pr4)f?o&DMM4w>Ksb{hF(0|wh+5_{vPow{V%TFzU2za&gjttNi zIyR9qA56dX52Qbv2aY^g`U7R43-p`#sO1A=K S2aKgfR+Yu^bQ*i-qu z%0mP;Ap)B~zZgO9lG^`325gOf?iUHF{~7jyGC)3L(eL(SQ70VzR~wLN18tnx(Cz2~ zctBl1kI)wAe+cxWHw*NW-d;=pd+>+wd$a@GBju*wFvabSaPtHiT!o#QFC+wBVwYo3s=y;z1jM+M=Fj!FZM>UzpL-eZzOT( zhmZmEfWa=%KE#V3-ZK5#v!Hz d{zc^{ctF~- z>DT-U`}5!fk$aj24`#uGdB7r`>oX5tU|d*b|N3V1lXmv%MGrvE(dXG)^-J*LA>$LE z7kut4`zE)v{@Op|(|@i#c>tM!12FQh?}PfA0`Bp%=%*RiXVzLDXnXtE@4B)5uR}a> zbNU}q+712pIrM`k^odG8dKtG$zwHmQI^c}tfjx5?egx3!e%JRm_64e+>`Ra1IRfLb z1KQ`SxmH{cZfyVS5m(&`{V}Y4j6J{b17`h6KWqZ&hfc( oR zxM%w!$F(mKy05kY&lco3%zvLCxBW+t*rxO+i=qGMvobx0-<7`VUu)ka`){=ew+Ovt zg%52_{&UbkUA8aJPWsk)gYWV4`dnxI%s?7^fGpq{ZQuu=VH{-t7w~K%_E<8`zS;V- zKTho*>;UQQul^1GT^HCt@I-q?)&4!QDgBndn?3sNKYKCQFU4LGKJ$n@Je$&w9@E$X z^p@iJ(v &`1(tq~1zc>0Vow-KR&vm!GUzT?Eqgnc)leZ9p)-Z*C!zqb=-$XG0 z^!8RfuQs5s>Q~qcz92(a_Q+KH?C*vCTr~UdTiR`JGuNH8v(J|FTiSEcPrBpmHRtmd zI2Jng0J=bXK);YY^rM?jzn?~X-Pe`GbAy{D)Y6D&1GY-EBcy%Bq?bKh?A>DD9DD!p z?{q02wno2sraGUkZv5dx+J8)&K$)No43Zr(*S`FEdL!4C)}WE}vJd%{S6-3VUw>Wp z?Aasv`T0^%P$2vE?L+Qhj~qB~K%eW)xH(=b_jU}TLD&BP*Pc9hz@Z=e0nkpLkWl}> z_5J^i(9Z7$(XG9~I3sY)`OGZ#_L06+Dy4E>UstcP-rU@xJ$&rxvo!n1Ao`P~KLU-8 z{zDgN4-&A6N!kPSYbQ&7sLufi`YtE2uN$S?e&5n>Y4(q#|KP!cc1j)T^QrUXMPFaP z_SoYO8S8G}Z$?AL4`;pE?7J5K8yWqy23>cCT2{=-)+A$X^-I9=e!@J@A&-;Ufc)`H}c(VI&;0x zrrGv()5mjP%jXzS{^|29?bLNXS0bC%p!YXI!;O457rjCEEzMkGf~B3$T}dXBO23tP z+Ci>;5UoM?C@bU@f9G1^X3=ly&ZeFH<@|RnOG--A&)fd)AUgjw?%izq{p(KJ`EP0v z2mU)P!+3t@X14DA=E2RR-|p${GZ9ETX=d+kJRZL$nSa0daI@&oUUxnZg0xd_xu>Vz lzF#z5%kSKX?YLH3ll^(hI(_`L*t#Iva2Ede*Z;>H_ + + + + +net6.0 +8 ++ Library ++ + + ++ + + + + diff --git a/CQRS_Simple.Domain/Products/Product.cs b/CQRS_Simple.Domain/Products/Product.cs new file mode 100644 index 0000000..8165aa8 --- /dev/null +++ b/CQRS_Simple.Domain/Products/Product.cs @@ -0,0 +1,29 @@ +using CQRS_Simple.Infrastructure; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using FluentValidation; + +namespace CQRS_Simple.Domain.Products +{ + [Table("Products")] + public class Product : Entity+ , IAggregateRoot + { + //[StringLength(256)] [Required] + public string Name { get; set; } + + //[StringLength(256)] + public string Code { get; set; } + + public string Description { get; set; } + } + + public class ProductValidator : AbstractValidator + { + public ProductValidator() + { + RuleFor(x => x.Name).NotNull(); + RuleFor(x => x.Name).Length(5, 256); + RuleFor(x => x.Code).Length(5, 256); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Domain/Products/Request/ProductsRequestInput.cs b/CQRS_Simple.Domain/Products/Request/ProductsRequestInput.cs new file mode 100644 index 0000000..9acbc6e --- /dev/null +++ b/CQRS_Simple.Domain/Products/Request/ProductsRequestInput.cs @@ -0,0 +1,20 @@ +using FluentValidation; + +namespace CQRS_Simple.Domain.Products.Request +{ + public class ProductsRequestInput + { + public int SkipCount { get; set; } + + public int MaxResultCount { get; set; } + } + + public class ProductValidator : AbstractValidator + { + public ProductValidator() + { + RuleFor(x => x.MaxResultCount).GreaterThanOrEqualTo(1).WithName("每页数量"); + RuleFor(x => x.SkipCount).GreaterThanOrEqualTo(0).WithName("忽略行数"); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.EntityFrameworkCore/CQRS_Simple.EntityFrameworkCore.csproj b/CQRS_Simple.EntityFrameworkCore/CQRS_Simple.EntityFrameworkCore.csproj new file mode 100644 index 0000000..082ccae --- /dev/null +++ b/CQRS_Simple.EntityFrameworkCore/CQRS_Simple.EntityFrameworkCore.csproj @@ -0,0 +1,29 @@ + + + diff --git a/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.Designer.cs b/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.Designer.cs new file mode 100644 index 0000000..5db6e2a --- /dev/null +++ b/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.Designer.cs @@ -0,0 +1,45 @@ +//+ + +Library +net6.0 +8 ++ + + + ++ + +all +runtime; build; native; contentfiles; analyzers; buildtransitive ++ + +all +runtime; build; native; contentfiles; analyzers; buildtransitive ++ + + ++ +using CQRS_Simple.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CQRS_Simple.EntityFrameworkCore.Migrations +{ + [DbContext(typeof(SimpleDbContext))] + [Migration("20220406070529_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("CQRS_Simple.Domain.Products.Product", b => + { + b.Property ("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property ("Code") + .HasColumnType("longtext"); + + b.Property ("Description") + .HasColumnType("longtext"); + + b.Property ("Name") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.cs b/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.cs new file mode 100644 index 0000000..c6233fa --- /dev/null +++ b/CQRS_Simple.EntityFrameworkCore/Migrations/20220406070529_InitialCreate.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CQRS_Simple.EntityFrameworkCore.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column (type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Name = table.Column (type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Code = table.Column (type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column (type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Products"); + } + } +} diff --git a/CQRS_Simple.EntityFrameworkCore/Migrations/SimpleDbContextModelSnapshot.cs b/CQRS_Simple.EntityFrameworkCore/Migrations/SimpleDbContextModelSnapshot.cs new file mode 100644 index 0000000..007438f --- /dev/null +++ b/CQRS_Simple.EntityFrameworkCore/Migrations/SimpleDbContextModelSnapshot.cs @@ -0,0 +1,43 @@ +// +using CQRS_Simple.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CQRS_Simple.EntityFrameworkCore.Migrations +{ + [DbContext(typeof(SimpleDbContext))] + partial class SimpleDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("CQRS_Simple.Domain.Products.Product", b => + { + b.Property ("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property ("Code") + .HasColumnType("longtext"); + + b.Property ("Description") + .HasColumnType("longtext"); + + b.Property ("Name") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CQRS_Simple.EntityFrameworkCore/SimpleDbContext.cs b/CQRS_Simple.EntityFrameworkCore/SimpleDbContext.cs new file mode 100644 index 0000000..34fc754 --- /dev/null +++ b/CQRS_Simple.EntityFrameworkCore/SimpleDbContext.cs @@ -0,0 +1,24 @@ +using System; +using CQRS_Simple.Domain.Products; +using Microsoft.EntityFrameworkCore; +using Serilog; + +namespace CQRS_Simple.EntityFrameworkCore +{ + public class SimpleDbContext : DbContext + { + protected SimpleDbContext() + { + } + + public DbSet Products { get; set; } + + public SimpleDbContext(DbContextOptions options) + : base(options) + { +#if DEBUG + Log.Debug($"SimpleDbContext Init"); +#endif + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/CQRS_Simple.Infrastructure.csproj b/CQRS_Simple.Infrastructure/CQRS_Simple.Infrastructure.csproj new file mode 100644 index 0000000..fe12023 --- /dev/null +++ b/CQRS_Simple.Infrastructure/CQRS_Simple.Infrastructure.csproj @@ -0,0 +1,24 @@ + + + diff --git a/CQRS_Simple.Infrastructure/Dapper/DapperExtensions.cs b/CQRS_Simple.Infrastructure/Dapper/DapperExtensions.cs new file mode 100644 index 0000000..a29a488 --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/DapperExtensions.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using Dapper; + +namespace CQRS_Simple.Infrastructure.Dapper +{ + public static class DapperExtensions + { + public static async Task+ + +net6.0 +8 ++ + ++ + + + + + + + + + + ++ InsertAsync (this IDbConnection db, string tableName, object param) + { + IEnumerable result = await db.QueryAsync (DynamicQuery.GetInsertQuery(tableName, param), param); + return result.First(); + } + + public static async Task UpdateAsync( + this IDbConnection db, + string tableName, object param) + { + return await db.ExecuteAsync(DynamicQuery.GetUpdateQuery(tableName, param), param); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/DapperRepository.cs b/CQRS_Simple.Infrastructure/Dapper/DapperRepository.cs new file mode 100644 index 0000000..0c5f08e --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/DapperRepository.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; +using Dapper; + +namespace CQRS_Simple.Infrastructure.Dapper +{ + public class DapperRepository : IDapperRepository where T : Entity + { + private readonly ISqlConnectionFactory _sqlConnectionFactory; + private readonly string _tableName; + + public DapperRepository(ISqlConnectionFactory sqlConnectionFactory) + { + _sqlConnectionFactory = sqlConnectionFactory; + var attr = typeof(T).GetCustomAttributes(typeof(TableAttribute), true).FirstOrDefault(); + _tableName = (attr as TableAttribute)?.Name; + } + + public async Task GetByIdAsync(TC id) + { + using var db = _sqlConnectionFactory.GetOpenConnection(); + return await db.QueryFirstOrDefaultAsync ( + $"SELECT * FROM {_tableName} WHERE Id=@Id", + new { Id = id }); + } + + public async Task AddAsync(T item) + { + using var db = _sqlConnectionFactory.GetOpenConnection(); + return await db.InsertAsync (_tableName, item); + } + + public async Task RemoveAsync(T item) + { + using var db = _sqlConnectionFactory.GetOpenConnection(); + return await db.ExecuteAsync( + $"DELETE FROM {_tableName} WHERE Id=@Id", + new { Id = item.Id }); + } + + public async Task UpdateAsync(T item) + { + using var db = _sqlConnectionFactory.GetOpenConnection(); + return await db.UpdateAsync(_tableName, item); + } + + public async Task > FindAsync(Expression > predicate) + { + IEnumerable items; + var result = DynamicQuery.GetDynamicQuery(_tableName, predicate); + using (var db = _sqlConnectionFactory.GetOpenConnection()) + { + items = await db.QueryAsync (result.Sql, (object)result.Param); + } + + return items; + } + + public async Task > GetAllAsync() + { + IEnumerable items; + using (var db = _sqlConnectionFactory.GetOpenConnection()) + { + items = await db.QueryAsync ( + $"SELECT * FROM {_tableName}" + ); + } + + return items; + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/DynamicQuery.cs b/CQRS_Simple.Infrastructure/Dapper/DynamicQuery.cs new file mode 100644 index 0000000..2f04a12 --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/DynamicQuery.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; + +namespace CQRS_Simple.Infrastructure.Dapper +{ + /// + /// Dynamic query class. + /// + public sealed class DynamicQuery + { + ///+ /// Gets the insert query. + /// + /// Name of the table. + /// The item. + ///+ /// The Sql query based on the item properties. + /// + public static string GetInsertQuery(string tableName, object item) + { + PropertyInfo[] props = item.GetType().GetProperties( + BindingFlags.Public | + BindingFlags.Instance); + var columns = props.Where(x => x.Name != "Id").Select(p => p.Name).ToArray(); + + return string.Format("INSERT INTO {0} ({1}) OUTPUT Inserted.Id VALUES (@{2})", + tableName, + string.Join(",", columns), + string.Join(",@", columns)); + } + + ///+ /// Gets the update query. + /// + /// Name of the table. + /// The item. + ///+ /// The Sql query based on the item properties. + /// + public static string GetUpdateQuery(string tableName, dynamic item) + { + PropertyInfo[] props = item.GetType().GetProperties(BindingFlags.Public | + BindingFlags.Instance); + + string[] columns = props.Where(x => x.Name != "Id").Select(p => p.Name).ToArray(); + + var parameters = columns.Select(name => name + "=@" + name).ToList(); + + return string.Format("UPDATE {0} SET {1} WHERE Id=@Id", tableName, string.Join(",", parameters)); + } + + ///+ /// Gets the dynamic query. + /// + /// Name of the table. + /// The expression. + ///A result object with the generated sql and dynamic params. + public static QueryResult GetDynamicQuery(string tableName, Expression > expression) + { + var queryProperties = new List (); + var body = (BinaryExpression)expression.Body; + IDictionary expando = new ExpandoObject(); + var builder = new StringBuilder(); + + // walk the tree and build up a list of query parameter objects + // from the left and right branches of the expression tree + WalkTree(body, ExpressionType.Default, ref queryProperties); + + // convert the query parms into a SQL string and dynamic property object + builder.Append("SELECT * FROM "); + builder.Append(tableName); + builder.Append(" WHERE "); + + for (int i = 0; i < queryProperties.Count(); i++) + { + QueryParameter item = queryProperties[i]; + + if (!string.IsNullOrEmpty(item.LinkingOperator) && i > 0) + { + builder.Append(string.Format("{0} {1} {2} @{1} ", item.LinkingOperator, item.PropertyName, + item.QueryOperator)); + } + else + { + builder.Append(string.Format("{0} {1} @{0} ", item.PropertyName, item.QueryOperator)); + } + + expando[item.PropertyName] = item.PropertyValue; + } + + return new QueryResult(builder.ToString().TrimEnd(), expando); + } + + /// + /// Walks the tree. + /// + /// The body. + /// Type of the linking. + /// The query properties. + private static void WalkTree(BinaryExpression body, ExpressionType linkingType, + ref ListqueryProperties) + { + if (body.NodeType != ExpressionType.AndAlso && body.NodeType != ExpressionType.OrElse) + { + string propertyName = GetPropertyName(body); + dynamic propertyValue = body.Right; + string opr = GetOperator(body.NodeType); + string link = GetOperator(linkingType); + + queryProperties.Add(new QueryParameter(link, propertyName, propertyValue.Value, opr)); + } + else + { + WalkTree((BinaryExpression)body.Left, body.NodeType, ref queryProperties); + WalkTree((BinaryExpression)body.Right, body.NodeType, ref queryProperties); + } + } + + /// + /// Gets the name of the property. + /// + /// The body. + ///The property name for the property expression. + private static string GetPropertyName(BinaryExpression body) + { + string propertyName = body.Left.ToString().Split(new char[] { '.' })[1]; + + if (body.Left.NodeType == ExpressionType.Convert) + { + // hack to remove the trailing ) when convering. + propertyName = propertyName.Replace(")", string.Empty); + } + + return propertyName; + } + + ///+ /// Gets the operator. + /// + /// The type. + ///+ /// The expression types SQL server equivalent operator. + /// + ///+ private static string GetOperator(ExpressionType type) + { + switch (type) + { + case ExpressionType.Equal: + return "="; + case ExpressionType.NotEqual: + return "!="; + case ExpressionType.LessThan: + return "<"; + case ExpressionType.GreaterThan: + return ">"; + case ExpressionType.AndAlso: + case ExpressionType.And: + return "AND"; + case ExpressionType.Or: + case ExpressionType.OrElse: + return "OR"; + case ExpressionType.Default: + return string.Empty; + default: + throw new NotImplementedException(); + } + } + } + + /// + /// Class that models the data structure in coverting the expression tree into SQL and Params. + /// + internal class QueryParameter + { + public string LinkingOperator { get; set; } + public string PropertyName { get; set; } + public object PropertyValue { get; set; } + public string QueryOperator { get; set; } + + ///+ /// Initializes a new instance of the + /// The linking operator. + /// Name of the property. + /// The property value. + /// The query operator. + internal QueryParameter(string linkingOperator, string propertyName, object propertyValue, string queryOperator) + { + this.LinkingOperator = linkingOperator; + this.PropertyName = propertyName; + this.PropertyValue = propertyValue; + this.QueryOperator = queryOperator; + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/IDapperRepository.cs b/CQRS_Simple.Infrastructure/Dapper/IDapperRepository.cs new file mode 100644 index 0000000..38460c7 --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/IDapperRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; + +namespace CQRS_Simple.Infrastructure.Dapper +{ + public interface IDapperRepositoryclass. + /// where T : Entity + { + Task AddAsync(T item); + Task RemoveAsync(T item); + Task UpdateAsync(T item); + Task GetByIdAsync(TC id); + Task > FindAsync(Expression > predicate); + Task > GetAllAsync(); + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/ISqlConnectionFactory.cs b/CQRS_Simple.Infrastructure/Dapper/ISqlConnectionFactory.cs new file mode 100644 index 0000000..a2f746a --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/ISqlConnectionFactory.cs @@ -0,0 +1,9 @@ +using System.Data; + +namespace CQRS_Simple.Infrastructure +{ + public interface ISqlConnectionFactory + { + IDbConnection GetOpenConnection(); + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/QueryResult.cs b/CQRS_Simple.Infrastructure/Dapper/QueryResult.cs new file mode 100644 index 0000000..a88e549 --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/QueryResult.cs @@ -0,0 +1,53 @@ +using System; + +namespace CQRS_Simple.Infrastructure +{ + /// + /// A result object with the generated sql and dynamic params. + /// + public class QueryResult + { + ///+ /// The _result + /// + private readonly Tuple_result; + + /// + /// Gets the SQL. + /// + ///+ /// The SQL. + /// + public string Sql + { + get + { + return _result.Item1; + } + } + + ///+ /// Gets the param. + /// + ///+ /// The param. + /// + public dynamic Param + { + get + { + return _result.Item2; + } + } + + ///+ /// Initializes a new instance of the + /// The SQL. + /// The param. + public QueryResult(string sql, dynamic param) + { + _result = new Tupleclass. + /// (sql, param); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Dapper/SqlConnectionFactory.cs b/CQRS_Simple.Infrastructure/Dapper/SqlConnectionFactory.cs new file mode 100644 index 0000000..2ed300e --- /dev/null +++ b/CQRS_Simple.Infrastructure/Dapper/SqlConnectionFactory.cs @@ -0,0 +1,44 @@ +using System; +using System.Data; +using System.Data.SqlClient; +using MySqlConnector; + +namespace CQRS_Simple.Infrastructure.Dapper +{ + public class SqlConnectionFactory : ISqlConnectionFactory, IDisposable + { + private readonly string _connectionString; + private IDbConnection _connection; + + public SqlConnectionFactory(string connectionString) + { + this._connectionString = connectionString; + } + + public IDbConnection GetOpenConnection() + { + if (this._connection == null || this._connection.State != ConnectionState.Open) + { + //this._connection = new SqlConnection(_connectionString); + this._connection = new MySqlConnection(_connectionString) + { + Site = null, + ProvideClientCertificatesCallback = null, + ProvidePasswordCallback = null, + RemoteCertificateValidationCallback = null + }; + this._connection.Open(); + } + + return this._connection; + } + + public void Dispose() + { + if (this._connection != null && this._connection.State == ConnectionState.Open) + { + this._connection.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/EntityBase.cs b/CQRS_Simple.Infrastructure/EntityBase.cs new file mode 100644 index 0000000..57822c0 --- /dev/null +++ b/CQRS_Simple.Infrastructure/EntityBase.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace CQRS_Simple.Infrastructure +{ + public class Entity : IEntity + { + [Key] public virtual TPrimaryKey Id { get; set; } + + private List _domainEvents; + + /// + /// Domain events occurred. + /// + protected IReadOnlyCollectionDomainEvents => _domainEvents?.AsReadOnly(); + + /// + /// Add domain event. + /// + /// + protected void AddDomainEvent(IDomainEvent domainEvent) + { + _domainEvents ??= new List(); + _domainEvents.Add(domainEvent); + } + + /// + /// Clead domain events. + /// + public void ClearDomainEvents() + { + _domainEvents?.Clear(); + } + + ///+ public override int GetHashCode() + { + return Id == null ? 0 : Id.GetHashCode(); + } + + /// + public override string ToString() + { + return $"[{GetType().Name} {Id}]"; + } + } + + public interface IEntity + { + TPrimaryKey Id { get; set; } + + void ClearDomainEvents(); + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/IAggregateRoot.cs b/CQRS_Simple.Infrastructure/IAggregateRoot.cs new file mode 100644 index 0000000..9628227 --- /dev/null +++ b/CQRS_Simple.Infrastructure/IAggregateRoot.cs @@ -0,0 +1,5 @@ +namespace CQRS_Simple.Infrastructure +{ + public interface IAggregateRoot + { } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/IDomainEvent.cs b/CQRS_Simple.Infrastructure/IDomainEvent.cs new file mode 100644 index 0000000..43b99bb --- /dev/null +++ b/CQRS_Simple.Infrastructure/IDomainEvent.cs @@ -0,0 +1,33 @@ +using System; + +namespace CQRS_Simple.Infrastructure +{ + public class DomainEvent : IDomainEvent + { + /// + /// The time when the event occurred. + /// + public DateTime EventTime { get; set; } + + ///+ /// The object which triggers the event (optional). + /// + public object EventSource { get; set; } + + ///+ /// Constructor. + /// + protected DomainEvent() + { + EventTime = DateTime.Now; + } + + } + + public interface IDomainEvent + { + DateTime EventTime { get; } + + object EventSource { get; set; } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/IocManager.cs b/CQRS_Simple.Infrastructure/IocManager.cs new file mode 100644 index 0000000..0928314 --- /dev/null +++ b/CQRS_Simple.Infrastructure/IocManager.cs @@ -0,0 +1,29 @@ +using Autofac; + +namespace CQRS_Simple.Infrastructure +{ + + public interface IIocManager + { + ILifetimeScope AutofacContainer { get; set; } + TService GetInstance(); + + } + + public class IocManager : IIocManager + { + public IocManager(ILifetimeScope container) + { + AutofacContainer = container; + } + /// + /// Autofac容器 + /// + public ILifetimeScope AutofacContainer { get; set; } + + public TService GetInstance() + { + return AutofacContainer.Resolve (); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/MQ/RabbitData.cs b/CQRS_Simple.Infrastructure/MQ/RabbitData.cs new file mode 100644 index 0000000..a11b449 --- /dev/null +++ b/CQRS_Simple.Infrastructure/MQ/RabbitData.cs @@ -0,0 +1,19 @@ +using System; + +namespace CQRS_Simple.API.Products.Handlers +{ + public class RabbitData + { + public string Type { get; private set; } + public object Request { get; private set; } + + public object Result { get; private set; } + + public RabbitData(Type type, object request, object result = null) + { + Type = $"{type}"; + Request = request; + Result = result; + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/MQ/RabbitListener.cs b/CQRS_Simple.Infrastructure/MQ/RabbitListener.cs new file mode 100644 index 0000000..e65251f --- /dev/null +++ b/CQRS_Simple.Infrastructure/MQ/RabbitListener.cs @@ -0,0 +1,102 @@ +using System; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Options; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; +using Serilog; + +namespace CQRS_Simple.Infrastructure.MQ +{ + public class RabbitListener : IHostedService + { + private readonly RabbitMQOptions _options; + private readonly IConnection connection; + private readonly IModel channel; + + public RabbitListener( + IOptions optionsAccessor + ) + { + _options = optionsAccessor.Value; + try + { + var factory = new ConnectionFactory() + { + UserName = _options.UserName, + Password = _options.Password, + HostName = _options.HostName, + Port = _options.Port + }; + this.connection = factory.CreateConnection(); + this.channel = connection.CreateModel(); + Log.Information($"RabbitMQ 连接成功"); + + } + catch (Exception ex) + { + Log.Error($"RabbitListener init error,ex:{ex.Message}"); + } + } + + + public async Task StartAsync(CancellationToken cancellationToken) + { + await Register(); + await Task.CompletedTask; + } + + protected string QueueName= "QueueName"; + protected string RouteKey; + + // 处理消息的方法 + public virtual async Task Register() + { + channel.ExchangeDeclare("message", ExchangeType.Topic, true, false, null); + channel.QueueDeclare(QueueName, true, false, false, null); + + channel.QueueBind(queue: QueueName, exchange: "message", routingKey: RouteKey); + + var consumer = new EventingBasicConsumer(channel); + + consumer.Received += async (model, ea) => + { + var body = ea.Body; + var message = Encoding.UTF8.GetString(body.ToArray()); + var result = await ProcessAsync(message); + Log.Information($"收到消息: {message} routerKey: { ea.RoutingKey}"); + if (result) + { + channel.BasicAck(ea.DeliveryTag, false); + } + await Task.Yield(); + }; + channel.BasicConsume(queue: QueueName, consumer: consumer); + + await Task.CompletedTask; + } + + public virtual Task ProcessAsync(string message) + { + throw new NotImplementedException(); + } + + public Task StopAsync(CancellationToken cancellationToken) + { + channel?.Dispose(); + connection?.Dispose(); + return Task.CompletedTask; + } + } + + public class RabbitMQOptions + { + public string UserName { get; set; } + public string Password { get; set; } + public string HostName { get; set; } + public int Port { get; set; } + public string QueryName { get; set; } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/MQ/RabbitPublisher.cs b/CQRS_Simple.Infrastructure/MQ/RabbitPublisher.cs new file mode 100644 index 0000000..dd87110 --- /dev/null +++ b/CQRS_Simple.Infrastructure/MQ/RabbitPublisher.cs @@ -0,0 +1,71 @@ +using System; +using System.Text; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using RabbitMQ.Client; +using Serilog; + +namespace CQRS_Simple.Infrastructure.MQ +{ + public class RabbitMQClient : IDisposable + { + private readonly RabbitMQOptions _options; + + private IModel _channel; + private IConnection _connection; + + public RabbitMQClient( + IOptions optionsAccessor + ) + { + _options = optionsAccessor.Value; + try + { + var factory = new ConnectionFactory() + { + UserName = _options.UserName, + Password = _options.Password, + HostName = _options.HostName, + Port = _options.Port + }; + this._connection = factory.CreateConnection(); + this._channel = _connection.CreateModel(); + Log.Information($"RabbitMQ Client 连接成功"); + } + catch (Exception ex) + { + Console.WriteLine($"RabbitListener init error,ex:{ex.Message}"); + } + } + + public virtual void PushMessage(object message, string queryName = null, string routerKey = "Test.*") + { + if (queryName == null) + queryName = _options.QueryName; + + var exchangeName = "message"; + + Log.Debug($"PushMessage queryName:{queryName} routingKey:{routerKey}"); + + //定义一个Direct类型交换机 + _channel.ExchangeDeclare(exchangeName, ExchangeType.Topic, true, false, null); + + //定义一个队列 + _channel.QueueDeclare(queryName, true, false, false, null); + + //将队列绑定到交换机 + _channel.QueueBind(queryName, exchangeName, routerKey, null); + + var sendBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); + + _channel.BasicPublish(exchangeName, routerKey, null, sendBytes); + } + + public void Dispose() + { + _channel?.Dispose(); + _connection?.Dispose(); + Log.Information($"RabbitMQ Client Dispose"); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/TimeInterceptor.cs b/CQRS_Simple.Infrastructure/TimeInterceptor.cs new file mode 100644 index 0000000..c60e7a7 --- /dev/null +++ b/CQRS_Simple.Infrastructure/TimeInterceptor.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using System.Linq; +using Castle.DynamicProxy; + + +namespace CQRS_Simple.Infrastructure +{ + /// + /// 拦截器 需要实现 IInterceptor接口 Intercept方法 + /// + public class CallLogger : IInterceptor + { + TextWriter _output; + + public CallLogger(TextWriter output) + { + _output = output; + } + + ///+ /// 拦截方法 打印被拦截的方法执行前的名称、参数和方法执行后的 返回结果 + /// + /// 包含被拦截方法的信息 + public void Intercept(IInvocation invocation) + { + if (invocation.Method.IsPublic) + { + _output.WriteLine("你正在调用方法 \"{0}\" 参数是 {1}... ", + invocation.Method.Name, + string.Join(", ", invocation.Arguments.Select(a => (a ?? "").ToString()).ToArray())); + + //在被拦截的方法执行完毕后 继续执行 + invocation.Proceed(); + + _output.WriteLine("方法执行完毕,返回结果:{0}", invocation.ReturnValue); + } + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Uow/IRepository.cs b/CQRS_Simple.Infrastructure/Uow/IRepository.cs new file mode 100644 index 0000000..8d05d8d --- /dev/null +++ b/CQRS_Simple.Infrastructure/Uow/IRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading.Tasks; + +namespace CQRS_Simple.Infrastructure.Uow +{ + public interface IRepositorywhere T : Entity + { + IUnitOfWork UnitOfWork { get; } + T GetById(TC id); + Task GetByIdAsync(TC id); + IEnumerable GetAll(); + IEnumerable Get(Expression > predicate); + void Add(T entity); + void Delete(T entity); + void Update(T entity); + + Task > GetAllAsync(); + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Uow/IUnitOfWork.cs b/CQRS_Simple.Infrastructure/Uow/IUnitOfWork.cs new file mode 100644 index 0000000..225372d --- /dev/null +++ b/CQRS_Simple.Infrastructure/Uow/IUnitOfWork.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Threading.Tasks; + +namespace CQRS_Simple.Infrastructure.Uow +{ + public interface IUnitOfWork : IDisposable + { + DbContext Context { get; } + int SaveChanges(); + Task SaveChangesAsync(); + + IRepository GetRepository () where T : Entity ; + void PrintKey(); + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Uow/Repository.cs b/CQRS_Simple.Infrastructure/Uow/Repository.cs new file mode 100644 index 0000000..270ebcd --- /dev/null +++ b/CQRS_Simple.Infrastructure/Uow/Repository.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace CQRS_Simple.Infrastructure.Uow +{ + public class Repository : IRepository where T : Entity + { + private readonly IUnitOfWork _unitOfWork; + + public Repository(IUnitOfWork unitOfWork) + { + _unitOfWork = unitOfWork; + } + public void Add(T entity) + { + _unitOfWork.Context.Set ().Add(entity); + } + + public void Delete(T entity) + { + T existing = _unitOfWork.Context.Set ().Find(entity); + if (existing != null) _unitOfWork.Context.Set ().Remove(existing); + } + + public IUnitOfWork UnitOfWork => _unitOfWork; + + public T GetById(TPrimaryKey id) + { + return _unitOfWork.Context.Set ().FirstOrDefault(x => id.Equals(x.Id)); + } + public Task GetByIdAsync(TPrimaryKey id) + { + return _unitOfWork.Context.Set ().FirstOrDefaultAsync(x => id.Equals(x.Id)); + } + + public IEnumerable GetAll() + { + return _unitOfWork.Context.Set ().AsEnumerable (); + } + + public IEnumerable Get(System.Linq.Expressions.Expression > predicate) + { + return _unitOfWork.Context.Set ().Where(predicate).AsEnumerable (); + } + + public void Update(T entity) + { + _unitOfWork.Context.Entry(entity).State = EntityState.Modified; + _unitOfWork.Context.Set ().Attach(entity); + } + + public async Task > GetAllAsync() + { + return await _unitOfWork.Context.Set ().ToListAsync(); + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Infrastructure/Uow/UnitOfWork.cs b/CQRS_Simple.Infrastructure/Uow/UnitOfWork.cs new file mode 100644 index 0000000..427cebf --- /dev/null +++ b/CQRS_Simple.Infrastructure/Uow/UnitOfWork.cs @@ -0,0 +1,116 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Storage; +using Serilog; + +namespace CQRS_Simple.Infrastructure.Uow +{ + public class UnitOfWork : IUnitOfWork + { + private readonly IIocManager _iocManager; + private Guid KEY { get; } + + public DbContext Context { get; } + + public IDbContextTransaction Transaction; + + public UnitOfWork(DbContext context, IIocManager iocManager) + { + _iocManager = iocManager; + Context = context; + + Transaction = context.Database.BeginTransaction(); + + KEY = Guid.NewGuid(); +#if DEBUG + Log.Information($"UnitOfWork Init {KEY}"); +#endif + } + public int SaveChanges() + { + return Context.SaveChanges(); + } + + public async Task SaveChangesAsync() + { + return await CommitAsync(); + } + + public IRepository GetRepository () where T : Entity + { + return _iocManager.GetInstance >(); + } + + public void PrintKey() + { + Log.Information($"PrintKey:{KEY}"); + } + + /// + /// 手动清理 + /// + public void CleanUp() + { + Commit(); + + Transaction?.Dispose(); + Context?.Dispose(); + +#if DEBUG + Log.Information($"Context CleanUp"); +#endif + } + + + private int Commit() + { + var result = 0; + try + { + result = Context.SaveChanges(); + Transaction?.Commit(); + return result; + } + catch (Exception e) + { + result = -1; + Transaction?.Rollback(); + Log.Error("Context Transaction Error"); + Log.Error(e.Message); + } + return result; + } + private async TaskCommitAsync() + { + var result = 0; + try + { + result = await Context.SaveChangesAsync(); + Transaction?.Commit(); + return result; + } + catch (Exception e) + { + result = -1; + if (Transaction != null) + await Transaction.RollbackAsync(); + Log.Error("Context Transaction Error"); + Log.Error(e.Message); + } + return result; + } + + + + public void Dispose() + { + Context?.Dispose(); +#if DEBUG + Log.Information($"Context Dispose"); + +#endif + } + } +} \ No newline at end of file diff --git a/CQRS_Simple.Tests/CQRS_Simple.Tests.csproj b/CQRS_Simple.Tests/CQRS_Simple.Tests.csproj new file mode 100644 index 0000000..c12d880 --- /dev/null +++ b/CQRS_Simple.Tests/CQRS_Simple.Tests.csproj @@ -0,0 +1,26 @@ + + + diff --git a/CQRS_Simple.Tests/UnitTest1.cs b/CQRS_Simple.Tests/UnitTest1.cs new file mode 100644 index 0000000..27da1c2 --- /dev/null +++ b/CQRS_Simple.Tests/UnitTest1.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace CQRS_Simple.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + + } + } +} diff --git a/CQRS_Simple.sln b/CQRS_Simple.sln new file mode 100644 index 0000000..010d1c1 --- /dev/null +++ b/CQRS_Simple.sln @@ -0,0 +1,58 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29519.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRS_Simple.API", "CQRS_Simple.API\CQRS_Simple.API.csproj", "{0B262E43-DCAD-4FB5-B394-E4DEE455C605}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRS_Simple.Domain", "CQRS_Simple.Domain\CQRS_Simple.Domain.csproj", "{D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRS_Simple.Infrastructure", "CQRS_Simple.Infrastructure\CQRS_Simple.Infrastructure.csproj", "{14AB059D-1475-4A91-AAF4-312FCB265E81}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRS_Simple.EntityFrameworkCore", "CQRS_Simple.EntityFrameworkCore\CQRS_Simple.EntityFrameworkCore.csproj", "{F6AFAF16-2BA5-4789-9EE4-A6F75CBBF4F7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{31A46403-BFDD-499A-8EC2-2EABDC096A47}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "API", "API", "{439AFE5F-24A5-4F70-9BEC-690E124C5D30}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CQRS_Simple.Tests", "CQRS_Simple.Tests\CQRS_Simple.Tests.csproj", "{824FCC5C-EE42-4AD8-8B00-DBC98EFA75A7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0B262E43-DCAD-4FB5-B394-E4DEE455C605}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B262E43-DCAD-4FB5-B394-E4DEE455C605}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B262E43-DCAD-4FB5-B394-E4DEE455C605}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B262E43-DCAD-4FB5-B394-E4DEE455C605}.Release|Any CPU.Build.0 = Release|Any CPU + {D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5}.Release|Any CPU.Build.0 = Release|Any CPU + {14AB059D-1475-4A91-AAF4-312FCB265E81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14AB059D-1475-4A91-AAF4-312FCB265E81}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14AB059D-1475-4A91-AAF4-312FCB265E81}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14AB059D-1475-4A91-AAF4-312FCB265E81}.Release|Any CPU.Build.0 = Release|Any CPU + {F6AFAF16-2BA5-4789-9EE4-A6F75CBBF4F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6AFAF16-2BA5-4789-9EE4-A6F75CBBF4F7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6AFAF16-2BA5-4789-9EE4-A6F75CBBF4F7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6AFAF16-2BA5-4789-9EE4-A6F75CBBF4F7}.Release|Any CPU.Build.0 = Release|Any CPU + {824FCC5C-EE42-4AD8-8B00-DBC98EFA75A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {824FCC5C-EE42-4AD8-8B00-DBC98EFA75A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {824FCC5C-EE42-4AD8-8B00-DBC98EFA75A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {824FCC5C-EE42-4AD8-8B00-DBC98EFA75A7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {0B262E43-DCAD-4FB5-B394-E4DEE455C605} = {439AFE5F-24A5-4F70-9BEC-690E124C5D30} + {D3EA4B65-1A8C-4F16-ABF9-837CDBD78CB5} = {31A46403-BFDD-499A-8EC2-2EABDC096A47} + {14AB059D-1475-4A91-AAF4-312FCB265E81} = {31A46403-BFDD-499A-8EC2-2EABDC096A47} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3BA00842-BEC3-4017-A48A-8EB7D8B1D18A} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md new file mode 100644 index 0000000..fb1067e --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +## 这是一个 DDD CQRS 的项目初始模版项目 + +### 后端技术栈 + +- .netcore 3.1 +- MediatR +- EntityFrameworkCore 3.1 +- Dapper +- RabbitMQ (Producer & Consumer ) +- AutoMapper 9 +- FluentValidation +- IdentityServer4 (todo) +- Serilog ++ + +net6.0 + +false ++ + ++ + + + + + + +all +runtime; build; native; contentfiles; analyzers; buildtransitive ++ +all +runtime; build; native; contentfiles; analyzers; buildtransitive +