From ffd115341c20dde07395446a5c3f49fa63559f59 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Fri, 18 Oct 2024 17:12:16 -0400 Subject: [PATCH] Adding an EntityBase overload for Vogen Ids Minor cleanup Updated packages --- Directory.Packages.props | 14 +++++++------- .../Ardalis.SharedKernel.csproj | 6 ++++-- src/Ardalis.SharedKernel/EntityBase.cs | 15 ++++++++++++++- .../DispatchAndClearEvents.cs | 2 +- .../DispatchAndClearEventsWithGuidId.cs | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e297b62..47c6df5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,13 +2,13 @@ - - - + + + - - - - + + + + \ No newline at end of file diff --git a/src/Ardalis.SharedKernel/Ardalis.SharedKernel.csproj b/src/Ardalis.SharedKernel/Ardalis.SharedKernel.csproj index 88314ff..38f8fab 100644 --- a/src/Ardalis.SharedKernel/Ardalis.SharedKernel.csproj +++ b/src/Ardalis.SharedKernel/Ardalis.SharedKernel.csproj @@ -13,9 +13,11 @@ https://github.com/ardalis/Ardalis.SharedKernel DDD;Shared Kernel;SharedKernel;Domain-Driven Design;Repository;Specification;ValueObject;Value Object;Ardalis;Clean;Clean Architecture;Clean Architecture Template icon.png - 1.6.0 + 2.1.0 - * Updated to latest NuGet Package Versions + * Updated packages + * Added default to TId property initializer + * Added another EntityBase overload to work with Vogen value objects true true diff --git a/src/Ardalis.SharedKernel/EntityBase.cs b/src/Ardalis.SharedKernel/EntityBase.cs index 0c38ff7..b7b0ffc 100644 --- a/src/Ardalis.SharedKernel/EntityBase.cs +++ b/src/Ardalis.SharedKernel/EntityBase.cs @@ -13,5 +13,18 @@ public abstract class EntityBase : HasDomainEventsBase public abstract class EntityBase : HasDomainEventsBase where TId : struct, IEquatable { - public TId Id { get; set; } + public TId Id { get; set; } = default!; } + +/// +/// For use with Vogen or similar tools for generating code for +/// strongly typed Ids. +/// +/// +/// +public abstract class EntityBase : HasDomainEventsBase + where T : EntityBase +{ + public TId Id { get; set; } = default!; +} + diff --git a/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEvents.cs b/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEvents.cs index 35fbf1c..24b2475 100644 --- a/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEvents.cs +++ b/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEvents.cs @@ -18,7 +18,7 @@ public void AddTestDomainEvent() } [Fact] - public async void CallsPublishAndClearDomainEvents() + public async Task CallsPublishAndClearDomainEvents() { // Arrange var mediatorMock = new Mock(); diff --git a/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEventsWithGuidId.cs b/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEventsWithGuidId.cs index c07eb39..bb5a5e8 100644 --- a/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEventsWithGuidId.cs +++ b/tests/Ardalis.SharedKernel.UnitTests/MediatRDomainEventDispatcherTests/DispatchAndClearEventsWithGuidId.cs @@ -18,7 +18,7 @@ public void AddTestDomainEvent() } [Fact] - public async void CallsPublishAndClearDomainEvents() + public async Task CallsPublishAndClearDomainEvents() { // Arrange var mediatorMock = new Mock();