diff --git a/README.md b/README.md index 0471924..192054d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ # Luck.Framework ++ ## change 2.0.1 version + + ### Update + + **1、Luck.DDD.Domain** + + Domain层中的基础聚合根和实体修改命名空间; + + ### Remove + + **1、Luck.EntityFrameworkCore** + + 删除EntityFrameworkCore层中使用的MediatR实现的领域事件,由业务控制,不在基础框架内封装; + + **2、Luck.DDD.Domain** + + 删除MediatR实现的领域事件通知; + ## change 2.0.0 version + ### Add + **1、Luck.AppModule** diff --git a/sample/Module.Sample/Domain/Order.cs b/sample/Module.Sample/Domain/Order.cs index 26b5432..1cdc805 100644 --- a/sample/Module.Sample/Domain/Order.cs +++ b/sample/Module.Sample/Domain/Order.cs @@ -1,4 +1,6 @@ using Luck.DDD.Domain; +using Luck.DDD.Domain.Domain.AggregateRoots; +using Luck.DDD.Domain.Domain.Entities; namespace Module.Sample.Domain { diff --git a/sample/Module.Sample/Services/OrderService.cs b/sample/Module.Sample/Services/OrderService.cs index 3faef62..a53cba6 100644 --- a/sample/Module.Sample/Services/OrderService.cs +++ b/sample/Module.Sample/Services/OrderService.cs @@ -39,7 +39,7 @@ public async Task CreateAndEventAsync() { var order = new Order("asdasdsa", "asdasdadas"); _aggregateRootRepository.Add(order); - order.AddDomainEvent(new OrderCreatedEto() { Id = order.Id, Name = order.Name }); + //order.AddDomainEvent(new OrderCreatedEto() { Id = order.Id, Name = order.Name }); _logger?.LogInformation("调用了CreateAndEventAsync()方法"); await _unitOfWork.CommitAsync(); //await _cache.AddAsync("order_a1", order); diff --git a/src/common.props b/src/common.props index f419f24..508d1bb 100644 --- a/src/common.props +++ b/src/common.props @@ -1,7 +1,7 @@  latest - 2.0.0 + 2.0.1 $(NoWarn);CS1591;CS0436 LGPL-3.0-only git diff --git a/src/framework/Luck.AppModule/Luck.AppModule.csproj b/src/framework/Luck.AppModule/Luck.AppModule.csproj index 755b024..720ced3 100644 --- a/src/framework/Luck.AppModule/Luck.AppModule.csproj +++ b/src/framework/Luck.AppModule/Luck.AppModule.csproj @@ -1,5 +1,5 @@ - + net6.0 enable diff --git a/src/framework/Luck.AutoDependencyInjection/AutoDependencyAppModule.cs b/src/framework/Luck.AutoDependencyInjection/AutoDependencyAppModule.cs index 23109b5..eebf270 100644 --- a/src/framework/Luck.AutoDependencyInjection/AutoDependencyAppModule.cs +++ b/src/framework/Luck.AutoDependencyInjection/AutoDependencyAppModule.cs @@ -10,7 +10,7 @@ namespace Luck.AutoDependencyInjection /// /// 自动注入模块,继承与AppModuleBase类进行实现 /// - public class AutoDependencyAppModule : Luck.AppModule.LuckAppModule + public class AutoDependencyAppModule : LuckAppModule { /// /// diff --git a/src/framework/Luck.AutoDependencyInjection/Luck.AutoDependencyInjection.csproj b/src/framework/Luck.AutoDependencyInjection/Luck.AutoDependencyInjection.csproj index 979fefd..67094d0 100644 --- a/src/framework/Luck.AutoDependencyInjection/Luck.AutoDependencyInjection.csproj +++ b/src/framework/Luck.AutoDependencyInjection/Luck.AutoDependencyInjection.csproj @@ -1,5 +1,5 @@  - + net6.0 enable diff --git a/src/framework/Luck.AutoDependencyInjection/build_package.sh b/src/framework/Luck.AutoDependencyInjection/build_package.sh new file mode 100755 index 0000000..27f38bc --- /dev/null +++ b/src/framework/Luck.AutoDependencyInjection/build_package.sh @@ -0,0 +1,7 @@ +#!/bin/bash +echo "请输入NUGET_API_KEY" +read NUGET_API_KEY +rm bin/Release/*.nupkg +dotnet build -c Release +dotnet pack -c Release +dotnet nuget push bin/Release/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootBase.cs b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootBase.cs new file mode 100644 index 0000000..d1b17dd --- /dev/null +++ b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootBase.cs @@ -0,0 +1,25 @@ + +namespace Luck.DDD.Domain.Domain.AggregateRoots +{ + public class AggregateRootBase : IAggregateRootBase + { + private string? _aggregateRootType; + + + private string AggregateRootName + { + get + { + var aggregateRootType = GetType(); + _aggregateRootType = aggregateRootType.FullName; + if (_aggregateRootType is null) + { + throw new ArgumentNullException(nameof(_aggregateRootType)); + } + + return _aggregateRootType; + } + } + + } +} diff --git a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootWithIdentity.cs b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootWithIdentity.cs similarity index 95% rename from src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootWithIdentity.cs rename to src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootWithIdentity.cs index ffc2d15..c367c77 100644 --- a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootWithIdentity.cs +++ b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/AggregateRootWithIdentity.cs @@ -1,4 +1,4 @@ -namespace Luck.DDD.Domain +namespace Luck.DDD.Domain.Domain.AggregateRoots { public class AggregateRootWithIdentity : AggregateRootBase { diff --git a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/FullAggregateRoot.cs b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/FullAggregateRoot.cs similarity index 89% rename from src/framework/Luck.DDD.Domain/Domian/AggregateRoots/FullAggregateRoot.cs rename to src/framework/Luck.DDD.Domain/Domain/AggregateRoots/FullAggregateRoot.cs index 0f4d4bf..72187f5 100644 --- a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/FullAggregateRoot.cs +++ b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/FullAggregateRoot.cs @@ -1,9 +1,6 @@ - +using Luck.Framework.Infrastructure; -using Luck.Framework; -using Luck.Framework.Infrastructure; - -namespace Luck.DDD.Domain +namespace Luck.DDD.Domain.Domain.AggregateRoots { public class FullAggregateRoot : AggregateRootWithIdentity, IUpdatable, ISoftDeletable { diff --git a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/IAggregateRootBase.cs b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/IAggregateRootBase.cs similarity index 56% rename from src/framework/Luck.DDD.Domain/Domian/AggregateRoots/IAggregateRootBase.cs rename to src/framework/Luck.DDD.Domain/Domain/AggregateRoots/IAggregateRootBase.cs index e61a89b..572ff23 100644 --- a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/IAggregateRootBase.cs +++ b/src/framework/Luck.DDD.Domain/Domain/AggregateRoots/IAggregateRootBase.cs @@ -1,4 +1,4 @@ -namespace Luck.DDD.Domain +namespace Luck.DDD.Domain.Domain.AggregateRoots { public interface IAggregateRootBase : IEntity { diff --git a/src/framework/Luck.DDD.Domain/Domain/Entities/Entity.cs b/src/framework/Luck.DDD.Domain/Domain/Entities/Entity.cs new file mode 100644 index 0000000..4e89fea --- /dev/null +++ b/src/framework/Luck.DDD.Domain/Domain/Entities/Entity.cs @@ -0,0 +1,11 @@ + +using Luck.DDD.Domain.Domain.Entities; + +namespace Luck.DDD.Domain.Domian.Entities +{ + public abstract class Entity : IEntityWithIdentity + { + + + } +} diff --git a/src/framework/Luck.DDD.Domain/Domian/Entities/EntityWithIdentity.cs b/src/framework/Luck.DDD.Domain/Domain/Entities/EntityWithIdentity.cs similarity index 72% rename from src/framework/Luck.DDD.Domain/Domian/Entities/EntityWithIdentity.cs rename to src/framework/Luck.DDD.Domain/Domain/Entities/EntityWithIdentity.cs index b8aa852..7015894 100644 --- a/src/framework/Luck.DDD.Domain/Domian/Entities/EntityWithIdentity.cs +++ b/src/framework/Luck.DDD.Domain/Domain/Entities/EntityWithIdentity.cs @@ -1,4 +1,6 @@ -namespace Luck.DDD.Domain +using Luck.DDD.Domain.Domian.Entities; + +namespace Luck.DDD.Domain.Domain.Entities { public abstract class EntityWithIdentity : Entity { diff --git a/src/framework/Luck.DDD.Domain/Domian/Entities/FullEntity.cs b/src/framework/Luck.DDD.Domain/Domain/Entities/FullEntity.cs similarity index 89% rename from src/framework/Luck.DDD.Domain/Domian/Entities/FullEntity.cs rename to src/framework/Luck.DDD.Domain/Domain/Entities/FullEntity.cs index ec11292..9a2b3eb 100644 --- a/src/framework/Luck.DDD.Domain/Domian/Entities/FullEntity.cs +++ b/src/framework/Luck.DDD.Domain/Domain/Entities/FullEntity.cs @@ -1,7 +1,6 @@ -using Luck.Framework; -using Luck.Framework.Infrastructure; +using Luck.Framework.Infrastructure; -namespace Luck.DDD.Domain +namespace Luck.DDD.Domain.Domain.Entities { public abstract class FullEntity : EntityWithIdentity, IUpdatable, ISoftDeletable { diff --git a/src/framework/Luck.DDD.Domain/Domian/Entities/IEntityWithIdentity.cs b/src/framework/Luck.DDD.Domain/Domain/Entities/IEntityWithIdentity.cs similarity index 64% rename from src/framework/Luck.DDD.Domain/Domian/Entities/IEntityWithIdentity.cs rename to src/framework/Luck.DDD.Domain/Domain/Entities/IEntityWithIdentity.cs index d26c10c..c544996 100644 --- a/src/framework/Luck.DDD.Domain/Domian/Entities/IEntityWithIdentity.cs +++ b/src/framework/Luck.DDD.Domain/Domain/Entities/IEntityWithIdentity.cs @@ -1,4 +1,4 @@ -namespace Luck.DDD.Domain +namespace Luck.DDD.Domain.Domain.Entities { public interface IEntityWithIdentity :IEntity diff --git a/src/framework/Luck.DDD.Domain/Domian/IEntity.cs b/src/framework/Luck.DDD.Domain/Domain/IEntity.cs similarity index 100% rename from src/framework/Luck.DDD.Domain/Domian/IEntity.cs rename to src/framework/Luck.DDD.Domain/Domain/IEntity.cs diff --git a/src/framework/Luck.DDD.Domain/Domian/ISoftDeletable.cs b/src/framework/Luck.DDD.Domain/Domain/ISoftDeletable.cs similarity index 100% rename from src/framework/Luck.DDD.Domain/Domian/ISoftDeletable.cs rename to src/framework/Luck.DDD.Domain/Domain/ISoftDeletable.cs diff --git a/src/framework/Luck.DDD.Domain/Domian/IUpdatable.cs b/src/framework/Luck.DDD.Domain/Domain/IUpdatable.cs similarity index 100% rename from src/framework/Luck.DDD.Domain/Domian/IUpdatable.cs rename to src/framework/Luck.DDD.Domain/Domain/IUpdatable.cs diff --git a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootBase.cs b/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootBase.cs deleted file mode 100644 index 3b4d679..0000000 --- a/src/framework/Luck.DDD.Domain/Domian/AggregateRoots/AggregateRootBase.cs +++ /dev/null @@ -1,53 +0,0 @@ -using MediatR; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Luck.DDD.Domain -{ - public class AggregateRootBase : IAggregateRootBase, IDomainEvents - { - private string? _aggregateRootType; - - - private string AggregateRootName - { - get - { - var aggregateRootType = GetType(); - _aggregateRootType = aggregateRootType.FullName; - if (_aggregateRootType is null) - { - throw new ArgumentNullException(nameof(_aggregateRootType)); - } - - return _aggregateRootType; - } - } - - - [NotMapped] - private readonly Queue domainEvents = new(); - public void AddDomainEvent(INotification notification) - { - domainEvents.Enqueue(notification); - } - - public void AddDomainEventIfAbsent(INotification notification) - { - if (!domainEvents.Contains(notification)) - { - domainEvents.Enqueue(notification); - } - } - - public void ClearDomainEvents() - { - domainEvents.Clear(); - } - - public IEnumerable GetDomainEvents() - { - return domainEvents; - } - - } -} diff --git a/src/framework/Luck.DDD.Domain/Domian/Entities/Entity.cs b/src/framework/Luck.DDD.Domain/Domian/Entities/Entity.cs deleted file mode 100644 index 83b2969..0000000 --- a/src/framework/Luck.DDD.Domain/Domian/Entities/Entity.cs +++ /dev/null @@ -1,12 +0,0 @@ - -using MediatR; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Luck.DDD.Domain -{ - public abstract class Entity : IEntityWithIdentity - { - - - } -} diff --git a/src/framework/Luck.DDD.Domain/Domian/Events/IDomainEvents.cs b/src/framework/Luck.DDD.Domain/Domian/Events/IDomainEvents.cs deleted file mode 100644 index 2dcc628..0000000 --- a/src/framework/Luck.DDD.Domain/Domian/Events/IDomainEvents.cs +++ /dev/null @@ -1,13 +0,0 @@ -using MediatR; - -namespace Luck.DDD.Domain -{ - public interface IDomainEvents - { - IEnumerable GetDomainEvents(); - void AddDomainEvent(INotification notification); - - void AddDomainEventIfAbsent(INotification notification); - public void ClearDomainEvents(); - } -} diff --git a/src/framework/Luck.DDD.Domain/Luck.DDD.Domain.csproj b/src/framework/Luck.DDD.Domain/Luck.DDD.Domain.csproj index 4ac2439..3fe9c1e 100644 --- a/src/framework/Luck.DDD.Domain/Luck.DDD.Domain.csproj +++ b/src/framework/Luck.DDD.Domain/Luck.DDD.Domain.csproj @@ -5,10 +5,6 @@ enable enable - - - - diff --git a/src/framework/Luck.DDD.Domain/Repositories/AggregateRootRepositoryBase.cs b/src/framework/Luck.DDD.Domain/Repositories/AggregateRootRepositoryBase.cs index b832362..5d84718 100644 --- a/src/framework/Luck.DDD.Domain/Repositories/AggregateRootRepositoryBase.cs +++ b/src/framework/Luck.DDD.Domain/Repositories/AggregateRootRepositoryBase.cs @@ -1,4 +1,5 @@ using System.Linq.Expressions; +using Luck.DDD.Domain.Domain.AggregateRoots; namespace Luck.DDD.Domain.Repositories { diff --git a/src/framework/Luck.DDD.Domain/Repositories/IAggregateRootRepository.cs b/src/framework/Luck.DDD.Domain/Repositories/IAggregateRootRepository.cs index 61d4e01..2041171 100644 --- a/src/framework/Luck.DDD.Domain/Repositories/IAggregateRootRepository.cs +++ b/src/framework/Luck.DDD.Domain/Repositories/IAggregateRootRepository.cs @@ -1,4 +1,6 @@ -namespace Luck.DDD.Domain.Repositories +using Luck.DDD.Domain.Domain.AggregateRoots; + +namespace Luck.DDD.Domain.Repositories { public interface IAggregateRootRepository : IWriteRepository, IRepository where TEntity : IAggregateRootBase diff --git a/src/framework/Luck.DDD.Domain/Repositories/IEntityRepository.cs b/src/framework/Luck.DDD.Domain/Repositories/IEntityRepository.cs index 6e1320d..59e9427 100644 --- a/src/framework/Luck.DDD.Domain/Repositories/IEntityRepository.cs +++ b/src/framework/Luck.DDD.Domain/Repositories/IEntityRepository.cs @@ -1,4 +1,6 @@ -namespace Luck.DDD.Domain.Repositories +using Luck.DDD.Domain.Domain.Entities; + +namespace Luck.DDD.Domain.Repositories { public interface IEntityRepository : IRepository where TEntity : IEntityWithIdentity diff --git a/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlAggregateRootRepository.cs b/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlAggregateRootRepository.cs index e0abc99..3bb74d5 100644 --- a/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlAggregateRootRepository.cs +++ b/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlAggregateRootRepository.cs @@ -1,3 +1,5 @@ +using Luck.DDD.Domain.Domain.AggregateRoots; + namespace Luck.DDD.Domain.SqlRepositories; public interface ISqlAggregateRootRepository:ISqlWriteRepository,ISqlRepositorywhere TEntity : IAggregateRootBase diff --git a/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlEntityRepository.cs b/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlEntityRepository.cs index 3b32377..0bb5b39 100644 --- a/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlEntityRepository.cs +++ b/src/framework/Luck.DDD.Domain/SqlRepositories/ISqlEntityRepository.cs @@ -1,3 +1,5 @@ +using Luck.DDD.Domain.Domain.Entities; + namespace Luck.DDD.Domain.SqlRepositories; public interface ISqlEntityRepository : diff --git a/src/framework/Luck.DDD.Domain/SqlRepositories/SqlAggregateRootRepositoryBase.cs b/src/framework/Luck.DDD.Domain/SqlRepositories/SqlAggregateRootRepositoryBase.cs index 4a7be31..50b67a9 100644 --- a/src/framework/Luck.DDD.Domain/SqlRepositories/SqlAggregateRootRepositoryBase.cs +++ b/src/framework/Luck.DDD.Domain/SqlRepositories/SqlAggregateRootRepositoryBase.cs @@ -1,4 +1,5 @@ using System.Data; +using Luck.DDD.Domain.Domain.AggregateRoots; namespace Luck.DDD.Domain.SqlRepositories; diff --git a/src/framework/Luck.Dapper/Repositories/DapperAggregateRootRepositoryBase.cs b/src/framework/Luck.Dapper/Repositories/DapperAggregateRootRepositoryBase.cs index f6abb15..2c54303 100644 --- a/src/framework/Luck.Dapper/Repositories/DapperAggregateRootRepositoryBase.cs +++ b/src/framework/Luck.Dapper/Repositories/DapperAggregateRootRepositoryBase.cs @@ -1,6 +1,7 @@ using System.Data; using Luck.Dapper.DbConnectionFactories; using Luck.DDD.Domain; +using Luck.DDD.Domain.Domain.AggregateRoots; using Luck.DDD.Domain.SqlRepositories; namespace Luck.Dapper.Repositories; diff --git a/src/framework/Luck.Dapper/Repositories/DapperEntityRepository.cs b/src/framework/Luck.Dapper/Repositories/DapperEntityRepository.cs index 09114a8..84f98c0 100644 --- a/src/framework/Luck.Dapper/Repositories/DapperEntityRepository.cs +++ b/src/framework/Luck.Dapper/Repositories/DapperEntityRepository.cs @@ -1,5 +1,6 @@ using Luck.Dapper.DbConnectionFactories; using Luck.DDD.Domain; +using Luck.DDD.Domain.Domain.Entities; using Luck.DDD.Domain.SqlRepositories; namespace Luck.Dapper.Repositories; diff --git a/src/framework/Luck.EntityFrameworkCore/DbContexts/MediatorExtensions.cs b/src/framework/Luck.EntityFrameworkCore/DbContexts/MediatorExtensions.cs deleted file mode 100644 index 6c0304a..0000000 --- a/src/framework/Luck.EntityFrameworkCore/DbContexts/MediatorExtensions.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Luck.DDD.Domain; -using MediatR; -using Microsoft.EntityFrameworkCore; - -namespace Luck.EntityFrameworkCore.DbContexts -{ - public static class MediatorExtensions - { - public static async Task DispatchDomainEventsAsync(this IMediator mediator, DbContext ctx, CancellationToken cancellationToken = default) - { - var domainEntities = ctx.ChangeTracker - .Entries() - .Where(x => x.Entity.GetDomainEvents().Any()); - - var domainEvents = domainEntities - .SelectMany(x => x.Entity.GetDomainEvents()) - .ToList();//加ToList()是为立即加载,否则会延迟执行,到foreach的时候已经被ClearDomainEvents()了 - - domainEntities.ToList() - .ForEach(entity => entity.Entity.ClearDomainEvents()); - - foreach (var domainEvent in domainEvents) - { - await mediator.Publish(domainEvent, cancellationToken); - } - } - } -} diff --git a/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreAggregateRootRepository.cs b/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreAggregateRootRepository.cs index 13873d1..ae96631 100644 --- a/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreAggregateRootRepository.cs +++ b/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreAggregateRootRepository.cs @@ -4,6 +4,7 @@ using Luck.EntityFrameworkCore.DbContexts; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; +using Luck.DDD.Domain.Domain.AggregateRoots; namespace Luck.EntityFrameworkCore.Repositories { diff --git a/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreEntityRepository.cs b/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreEntityRepository.cs index 78cfedb..2e7fcba 100644 --- a/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreEntityRepository.cs +++ b/src/framework/Luck.EntityFrameworkCore/Repositories/EFCoreEntityRepository.cs @@ -3,6 +3,7 @@ using Luck.EntityFrameworkCore.DbContexts; using Microsoft.EntityFrameworkCore; using System.Linq.Expressions; +using Luck.DDD.Domain.Domain.Entities; namespace Luck.EntityFrameworkCore.Repositories {