diff --git a/CHANGELOG.md b/CHANGELOG.md index b1193de0..3c87ede3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [v6.4.0](https://github.com/Genocs/genocs-library/compare/v6.3.0...v6.4.0) + +> 10 November 2024 + +- Refactor MongoDB repository structure and base classes [`98e24b1`](https://github.com/Genocs/genocs-library/commit/98e24b1aab96ca4276924a822e0b5ffec50c3e9b) +- Update package references to version 6.4.0 across multiple projects [`6fdf470`](https://github.com/Genocs/genocs-library/commit/6fdf470b2234bf8a08e70deb251bef4f2cbd4edc) +- Refactor: Replace IIdentifiable with IEntity [`a21e330`](https://github.com/Genocs/genocs-library/commit/a21e33004ff115b383556835096ee02bd94c9f0f) +- Update packages, refactor code, and improve readability [`0a2d5be`](https://github.com/Genocs/genocs-library/commit/0a2d5be49e6e3d28e56da01aea2b72c21fa83568) +- Remove project refs and add using directive [`a5f189b`](https://github.com/Genocs/genocs-library/commit/a5f189be8c47d0294ca93dea5804a11b67bcc84d) +- Update to version 6.3.0 and refactor codebase [`713fb84`](https://github.com/Genocs/genocs-library/commit/713fb847400afccc205061d854db1ee22159d62d) +- Standardize property names and update audit fields [`c10e995`](https://github.com/Genocs/genocs-library/commit/c10e995b229fa8958e7f0585679562c711a56c22) +- Refactor MongoDB repository structure and update usings [`c3a8bac`](https://github.com/Genocs/genocs-library/commit/c3a8baca5d49ee7999be1e59384fea5c8b2d36d2) +- Refactor AzureInitializer and update MongoDB.Driver [`42dfe53`](https://github.com/Genocs/genocs-library/commit/42dfe53d120dbd53fe8018bdd418f1d2d9208c0f) +- Refactor null checks and exception handling [`7da092d`](https://github.com/Genocs/genocs-library/commit/7da092d0fecec393297dac85cf0a11e6fe6df95c) +- Update CHANGELOG for v6.3.0 release [`2e5eb47`](https://github.com/Genocs/genocs-library/commit/2e5eb47693439d55f9974402bab3f923993f117c) +- Update package versions in multiple project files [`106fc31`](https://github.com/Genocs/genocs-library/commit/106fc319c0411d90a6499bb4477b6f80cbe585f2) +- Refactor Entity and IAggregateRoot for simplicity [`3ccf665`](https://github.com/Genocs/genocs-library/commit/3ccf665db0c7e8eaceb50fa13d14c1ff4faa22e6) + #### [v6.3.0](https://github.com/Genocs/genocs-library/compare/v6.2.0...v6.3.0) > 3 November 2024 diff --git a/Directory.Build.props b/Directory.Build.props index 7868a2c7..49772f3a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,9 @@ + enable enable @@ -51,10 +55,12 @@ - + + + + + + true diff --git a/src/Genocs.Auth/Genocs.Auth.csproj b/src/Genocs.Auth/Genocs.Auth.csproj index 1c19263c..924792ef 100644 --- a/src/Genocs.Auth/Genocs.Auth.csproj +++ b/src/Genocs.Auth/Genocs.Auth.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/src/Genocs.Common/Types/IIdentifiable.cs b/src/Genocs.Common/Types/IIdentifiable.cs index 59e3ff30..e7ff2efb 100644 --- a/src/Genocs.Common/Types/IIdentifiable.cs +++ b/src/Genocs.Common/Types/IIdentifiable.cs @@ -10,10 +10,4 @@ public interface IIdentifiable /// The Id getter. /// T Id { get; } - - /// - /// Checks if this entity is transient (not persisted to database and it has not an ). - /// - /// True, if this entity is transient, otherwise false. - bool IsTransient(); } \ No newline at end of file diff --git a/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj b/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj index 26499d5b..69c454cc 100644 --- a/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj +++ b/src/Genocs.Core.Demo.Contracts/Genocs.Core.Demo.Contracts.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Genocs.Core.Demo.Domain/Aggregates/BaseAggregate.cs b/src/Genocs.Core.Demo.Domain/Aggregates/BaseAggregate.cs index e074b90e..f0eede68 100644 --- a/src/Genocs.Core.Demo.Domain/Aggregates/BaseAggregate.cs +++ b/src/Genocs.Core.Demo.Domain/Aggregates/BaseAggregate.cs @@ -1,14 +1,24 @@ using Genocs.Core.Domain.Entities; using Genocs.Core.Domain.Entities.Auditing; -using Genocs.Persistence.MongoDb.Repositories.Clean; +using Genocs.Persistence.MongoDb.Domain.Entities; using MongoDB.Bson; namespace Genocs.Core.Demo.Domain.Aggregates; /// /// Base aggregate class used for all entities. +/// This class is used to define some common properties for all entities. /// public class BaseAggregate : AggregateRoot, IMongoDbEntity, IHasCreationTime { - public DateTime CreationTime { get; set; } = DateTime.UtcNow; + public BaseAggregate() + { + // Set the unique identifier for the entity generates a new ObjectId. + Id = ObjectId.GenerateNewId(); + } + + /// + /// Creation time of this entity. + /// + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; } \ No newline at end of file diff --git a/src/Genocs.Core.Demo.Domain/Aggregates/Order.cs b/src/Genocs.Core.Demo.Domain/Aggregates/Order.cs index f9553296..0a8c3080 100644 --- a/src/Genocs.Core.Demo.Domain/Aggregates/Order.cs +++ b/src/Genocs.Core.Demo.Domain/Aggregates/Order.cs @@ -1,13 +1,10 @@ -using Genocs.Core.Domain.Entities; -using Genocs.Core.Domain.Entities.Auditing; -using Genocs.Core.Domain.Repositories; -using Genocs.Persistence.MongoDb.Repositories.Clean; +using Genocs.Core.Domain.Repositories; using MongoDB.Bson; namespace Genocs.Core.Demo.Domain.Aggregates; [TableMapping("Orders")] -public class Order : AggregateRoot, IMongoDbEntity, IHasCreationTime +public class Order : BaseAggregate { public Order(string orderId, string userId, decimal amount, string currency) { @@ -19,7 +16,6 @@ public Order(string orderId, string userId, decimal amount, string currency) public string OrderId { get; set; } = ObjectId.GenerateNewId().ToString(); public string UserId { get; set; } = default!; - public DateTime CreationTime { get; set; } = DateTime.UtcNow; public decimal Amount { get; set; } public string Currency { get; set; } = default!; } diff --git a/src/Genocs.Core.Demo.Domain/Aggregates/User.cs b/src/Genocs.Core.Demo.Domain/Aggregates/User.cs index ac54b661..94f13764 100644 --- a/src/Genocs.Core.Demo.Domain/Aggregates/User.cs +++ b/src/Genocs.Core.Demo.Domain/Aggregates/User.cs @@ -1,32 +1,20 @@ -using Genocs.Common.Types; -using Genocs.Core.Domain.Entities.Auditing; -using Genocs.Core.Domain.Repositories; -using MongoDB.Bson; +using Genocs.Core.Domain.Repositories; namespace Genocs.Core.Demo.Domain.Aggregates; [TableMapping("Users")] -public class User : IIdentifiable, IHasCreationTime +public class User : BaseAggregate { - - public ObjectId Id { get; set; } public string UserId { get; set; } = default!; - public DateTime CreationTime { get; set; } = DateTime.UtcNow; public string Username { get; set; } = default!; public decimal Age { get; set; } public string Country { get; set; } = default!; public User(string userId, string username, decimal age, string country) { - Id = ObjectId.GenerateNewId(); UserId = userId; Username = username; Age = age; Country = country; } - - public bool IsTransient() - { - return true; - } } diff --git a/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj b/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj index 7aa9facc..39f3fc59 100644 --- a/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj +++ b/src/Genocs.Core.Demo.Domain/Genocs.Core.Demo.Domain.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Genocs.Core.Demo.WebApi/Controllers/MongoDbController.cs b/src/Genocs.Core.Demo.WebApi/Controllers/MongoDbController.cs index ddc0be37..5fbd6f2d 100644 --- a/src/Genocs.Core.Demo.WebApi/Controllers/MongoDbController.cs +++ b/src/Genocs.Core.Demo.WebApi/Controllers/MongoDbController.cs @@ -1,5 +1,5 @@ using Genocs.Core.Demo.Domain.Aggregates; -using Genocs.Persistence.MongoDb.Repositories; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Microsoft.AspNetCore.Mvc; namespace Genocs.Core.Demo.WebApi.Controllers; diff --git a/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj b/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj index 9c4987ca..8b857be6 100644 --- a/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj +++ b/src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj @@ -22,21 +22,20 @@ - - - - - - - - - - + + + + + + + + + - - + + diff --git a/src/Genocs.Core.Demo.Worker/Consumers/SubmitOrderConsumer.cs b/src/Genocs.Core.Demo.Worker/Consumers/SubmitOrderConsumer.cs index a2a7873f..9c320201 100644 --- a/src/Genocs.Core.Demo.Worker/Consumers/SubmitOrderConsumer.cs +++ b/src/Genocs.Core.Demo.Worker/Consumers/SubmitOrderConsumer.cs @@ -1,6 +1,6 @@ using Genocs.Core.Demo.Contracts; using Genocs.Core.Demo.Domain.Aggregates; -using Genocs.Persistence.MongoDb.Repositories; +using Genocs.Persistence.MongoDb.Domain.Repositories; using MassTransit; namespace Genocs.Core.Demo.Worker.Consumers; diff --git a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj index e943a41b..f3eef8fe 100644 --- a/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj +++ b/src/Genocs.Core.Demo.Worker/Genocs.Core.Demo.Worker.csproj @@ -16,14 +16,14 @@ - - - + + + - + diff --git a/src/Genocs.Core.Demo.Worker/Program.cs b/src/Genocs.Core.Demo.Worker/Program.cs index f9cc495e..935d0cb5 100644 --- a/src/Genocs.Core.Demo.Worker/Program.cs +++ b/src/Genocs.Core.Demo.Worker/Program.cs @@ -7,9 +7,8 @@ using Genocs.Core.Demo.Worker.Consumers; using Genocs.Core.Demo.Worker.Handlers; using Genocs.Logging; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Genocs.Persistence.MongoDb.Extensions; -using Genocs.Persistence.MongoDb.Repositories; -using Genocs.Persistence.MongoDb.Repositories.Clean; using Genocs.ServiceBusAzure.Configurations; using Genocs.ServiceBusAzure.Queues; using Genocs.ServiceBusAzure.Queues.Interfaces; diff --git a/src/Genocs.Core/Builders/Extensions.cs b/src/Genocs.Core/Builders/Extensions.cs index 10638e44..72fa6c39 100644 --- a/src/Genocs.Core/Builders/Extensions.cs +++ b/src/Genocs.Core/Builders/Extensions.cs @@ -14,8 +14,8 @@ public static class Extensions /// /// The Builder. /// - /// - /// + /// The service collection. + /// The configuration. /// The builder. public static IGenocsBuilder AddGenocs(this IServiceCollection services, IConfiguration? configuration = null) { diff --git a/src/Genocs.Core/Collections/Extensions/ListExtensions.cs b/src/Genocs.Core/Collections/Extensions/ListExtensions.cs index 5738f16e..44a21f72 100644 --- a/src/Genocs.Core/Collections/Extensions/ListExtensions.cs +++ b/src/Genocs.Core/Collections/Extensions/ListExtensions.cs @@ -6,11 +6,11 @@ public static class ListExtensions { /// - /// Sort a list by a topological sorting, which consider their dependencies + /// Sort a list by a topological sorting, which consider their dependencies. /// /// The type of the members of values. - /// A list of objects to sort - /// Function to resolve the dependencies + /// A list of objects to sort. + /// Function to resolve the dependencies. /// public static List SortByDependencies(this IEnumerable source, Func> getDependencies) { diff --git a/src/Genocs.Core/Collections/TypeList.cs b/src/Genocs.Core/Collections/TypeList.cs index 0b8013c1..d8c636c6 100644 --- a/src/Genocs.Core/Collections/TypeList.cs +++ b/src/Genocs.Core/Collections/TypeList.cs @@ -20,7 +20,13 @@ public class TypeList : ITypeList /// Gets the count. /// /// The count. - public int Count { get { return _typeList.Count; } } + public int Count + { + get + { + return _typeList.Count; + } + } /// /// Gets a value indicating whether this instance is read only. diff --git a/src/Genocs.Core/Domain/Entities/Auditing/AuditedAggregateRoot.cs b/src/Genocs.Core/Domain/Entities/Auditing/AuditedAggregateRoot.cs index 4433ee83..e3e831cc 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/AuditedAggregateRoot.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/AuditedAggregateRoot.cs @@ -21,12 +21,12 @@ public abstract class AuditedAggregateRoot : CreationAuditedAggrega /// /// Last modification date of this entity. /// - public virtual DateTime? LastModificationTime { get; set; } + public virtual DateTime? LastUpdate { get; set; } /// /// Last modifier user of this entity. /// - public virtual long? LastModifierUserId { get; set; } + public virtual long? UpdatedBy { get; set; } } /// @@ -48,5 +48,5 @@ public abstract class AuditedAggregateRoot : AuditedAggregat /// Reference to the last modifier user of this entity. /// [ForeignKey("LastModifierUserId")] - public virtual TUser? LastModifierUser { get; set; } + public virtual TUser? UpdatedByUser { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/AuditedEntity.cs b/src/Genocs.Core/Domain/Entities/Auditing/AuditedEntity.cs index e81dd13b..3476f704 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/AuditedEntity.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/AuditedEntity.cs @@ -21,12 +21,12 @@ public abstract class AuditedEntity : CreationAuditedEntity /// Last modification date of this entity. /// - public virtual DateTime? LastModificationTime { get; set; } + public virtual DateTime? LastUpdate { get; set; } /// /// Last modifier user of this entity. /// - public virtual long? LastModifierUserId { get; set; } + public virtual long? UpdatedBy { get; set; } } /// @@ -48,5 +48,5 @@ public abstract class AuditedEntity : AuditedEntity [ForeignKey("LastModifierUserId")] - public virtual TUser? LastModifierUser { get; set; } + public virtual TUser? UpdatedByUser { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedAggregateRoot.cs b/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedAggregateRoot.cs index 66e69619..8b9e04af 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedAggregateRoot.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedAggregateRoot.cs @@ -22,12 +22,12 @@ public abstract class CreationAuditedAggregateRoot : AggregateRoot< /// /// Creation time of this entity. /// - public virtual DateTime CreationTime { get; set; } + public virtual DateTime CreatedAt { get; set; } /// /// Creator of this entity. /// - public virtual long? CreatorUserId { get; set; } + public virtual long CreatorUserId { get; set; } /// /// Constructor. @@ -35,7 +35,7 @@ public abstract class CreationAuditedAggregateRoot : AggregateRoot< protected CreationAuditedAggregateRoot() { // CreationTime = Clock.Now; // Manage time zone - CreationTime = DateTime.Now; + CreatedAt = DateTime.Now; } } diff --git a/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedEntity.cs b/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedEntity.cs index 8bb8195d..9299acb6 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedEntity.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/CreationAuditedEntity.cs @@ -1,7 +1,5 @@ using System.ComponentModel.DataAnnotations.Schema; -// using Genocs.Timing; - namespace Genocs.Core.Domain.Entities.Auditing; /// @@ -23,12 +21,12 @@ public abstract class CreationAuditedEntity : Entity, /// /// Creation time of this entity. /// - public virtual DateTime CreationTime { get; set; } + public virtual DateTime CreatedAt { get; set; } /// /// Creator of this entity. /// - public virtual long? CreatorUserId { get; set; } + public virtual long CreatorUserId { get; set; } /// /// Constructor. @@ -36,7 +34,7 @@ public abstract class CreationAuditedEntity : Entity, protected CreationAuditedEntity() { // CreationTime = Clock.Now; - CreationTime = DateTime.Now; + CreatedAt = DateTime.Now; } } diff --git a/src/Genocs.Core/Domain/Entities/Auditing/EntityAuditingHelper.cs b/src/Genocs.Core/Domain/Entities/Auditing/EntityAuditingHelper.cs index ac66f190..e05e7853 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/EntityAuditingHelper.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/EntityAuditingHelper.cs @@ -21,11 +21,10 @@ public static void SetCreationAuditProperties( return; } - if (entityWithCreationTime.CreationTime == default(DateTime)) + if (entityWithCreationTime.CreatedAt == default(DateTime)) { // entityWithCreationTime.CreationTime = Clock.Now; - entityWithCreationTime.CreationTime = DateTime.Now; - + // entityWithCreationTime.CreatedAt = DateTime.Now; } if (!(entityAsObj is ICreationAudited)) @@ -64,7 +63,7 @@ public static void SetCreationAuditProperties( //} // Finally, set CreatorUserId! - entity.CreatorUserId = userId; + entity.CreatorUserId = userId.Value; } public static void SetModificationAuditProperties( @@ -77,7 +76,7 @@ public static void SetModificationAuditProperties( if (entityAsObj is IHasModificationTime) { // entityAsObj.As().LastModificationTime = Clock.Now; - entityAsObj.As().LastModificationTime = DateTime.Now; + entityAsObj.As().LastUpdate = DateTime.Now; } if (!(entityAsObj is IModificationAudited)) @@ -91,7 +90,7 @@ public static void SetModificationAuditProperties( if (userId == null) { // Unknown user - entity.LastModifierUserId = null; + entity.UpdatedBy = null; return; } @@ -116,6 +115,6 @@ public static void SetModificationAuditProperties( */ // Finally, set LastModifierUserId! - entity.LastModifierUserId = userId; + entity.UpdatedBy = userId; } } diff --git a/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedAggregateRoot.cs b/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedAggregateRoot.cs index dbdcc4f4..63f29d02 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedAggregateRoot.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedAggregateRoot.cs @@ -26,12 +26,12 @@ public abstract class FullAuditedAggregateRoot : AuditedAggregateRo /// /// Which user deleted this entity. /// - public virtual long? DeleterUserId { get; set; } + public virtual long? DeletedBy { get; set; } /// /// Deletion time of this entity. /// - public virtual DateTime? DeletionTime { get; set; } + public virtual DateTime? DeletedAt { get; set; } } /// @@ -52,15 +52,15 @@ public abstract class FullAuditedAggregateRoot : AuditedAggr /// Reference to the deleter user of this entity. /// [ForeignKey("DeleterUserId")] - public virtual TUser DeleterUser { get; set; } + public virtual TUser DeletedByUser { get; set; } /// /// Which user deleted this entity. /// - public virtual long? DeleterUserId { get; set; } + public virtual long? DeletedBy { get; set; } /// /// Deletion time of this entity. /// - public virtual DateTime? DeletionTime { get; set; } + public virtual DateTime? DeletedAt { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedEntity.cs b/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedEntity.cs index 8309b385..72a30ccb 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedEntity.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/FullAuditedEntity.cs @@ -27,12 +27,12 @@ public abstract class FullAuditedEntity : AuditedEntity /// It determines the user who deleted this entity. /// - public virtual long? DeleterUserId { get; set; } + public virtual long? DeletedBy { get; set; } /// /// Deletion time of this entity. /// - public virtual DateTime? DeletionTime { get; set; } + public virtual DateTime? DeletedAt { get; set; } } /// @@ -45,7 +45,7 @@ public abstract class FullAuditedEntity : AuditedEntity { /// - /// Is this entity Deleted? + /// It determines if the entity is deleted. /// public virtual bool IsDeleted { get; set; } @@ -53,15 +53,15 @@ public abstract class FullAuditedEntity : AuditedEntity [ForeignKey("DeleterUserId")] - public virtual TUser DeleterUser { get; set; } + public virtual TUser? DeletedByUser { get; set; } /// /// Which user deleted this entity. /// - public virtual long? DeleterUserId { get; set; } + public virtual long? DeletedBy { get; set; } /// /// Deletion time of this entity. /// - public virtual DateTime? DeletionTime { get; set; } + public virtual DateTime? DeletedAt { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/ICreationAudited.cs b/src/Genocs.Core/Domain/Entities/Auditing/ICreationAudited.cs index 9ffac146..8b2082b0 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/ICreationAudited.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/ICreationAudited.cs @@ -9,7 +9,7 @@ public interface ICreationAudited : IHasCreationTime /// /// Id of the creator user of this entity. /// - long? CreatorUserId { get; set; } + long CreatorUserId { get; set; } } /// diff --git a/src/Genocs.Core/Domain/Entities/Auditing/IDeletionAudited.cs b/src/Genocs.Core/Domain/Entities/Auditing/IDeletionAudited.cs index bfa83bab..125de9aa 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/IDeletionAudited.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/IDeletionAudited.cs @@ -8,7 +8,7 @@ public interface IDeletionAudited : IHasDeletionTime /// /// Which user deleted this entity. /// - long? DeleterUserId { get; set; } + long? DeletedBy { get; set; } } /// @@ -21,5 +21,5 @@ public interface IDeletionAudited : IDeletionAudited /// /// Reference to the deleter user of this entity. /// - TUser DeleterUser { get; set; } + TUser? DeletedByUser { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/IHasCreationTime.cs b/src/Genocs.Core/Domain/Entities/Auditing/IHasCreationTime.cs index 8e0ca32f..b8867ce7 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/IHasCreationTime.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/IHasCreationTime.cs @@ -1,13 +1,13 @@ namespace Genocs.Core.Domain.Entities.Auditing; /// -/// An entity can implement this interface if of this entity must be stored. -/// is automatically set when saving to database. +/// An entity can implement this interface if of this entity must be stored. +/// is automatically set when saving to database. /// public interface IHasCreationTime { /// /// Creation time of this entity. /// - DateTime CreationTime { get; set; } + DateTime CreatedAt { get; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/IHasDeletionTime.cs b/src/Genocs.Core/Domain/Entities/Auditing/IHasDeletionTime.cs index 450bfc1b..9adc7903 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/IHasDeletionTime.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/IHasDeletionTime.cs @@ -1,13 +1,13 @@ namespace Genocs.Core.Domain.Entities.Auditing; /// -/// An entity can implement this interface if of this entity must be stored. -/// is automatically set when deleting . +/// An entity can implement this interface if of this entity must be stored. +/// is automatically set when deleting . /// public interface IHasDeletionTime : ISoftDelete { /// /// Deletion time of this entity. /// - DateTime? DeletionTime { get; set; } + DateTime? DeletedAt { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/IHasModificationTime.cs b/src/Genocs.Core/Domain/Entities/Auditing/IHasModificationTime.cs index 80519008..4c0c647b 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/IHasModificationTime.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/IHasModificationTime.cs @@ -1,16 +1,13 @@ -namespace Genocs.Core.Domain.Entities.Auditing -{ - using System; +namespace Genocs.Core.Domain.Entities.Auditing; +/// +/// An entity can implement this interface if of this entity must be stored. +/// is automatically set when updating . +/// +public interface IHasModificationTime +{ /// - /// An entity can implement this interface if of this entity must be stored. - /// is automatically set when updating . + /// The last modified time for this entity. /// - public interface IHasModificationTime - { - /// - /// The last modified time for this entity. - /// - DateTime? LastModificationTime { get; set; } - } + DateTime? LastUpdate { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Auditing/IModificationAudited.cs b/src/Genocs.Core/Domain/Entities/Auditing/IModificationAudited.cs index bdcd8c3a..d12f0438 100644 --- a/src/Genocs.Core/Domain/Entities/Auditing/IModificationAudited.cs +++ b/src/Genocs.Core/Domain/Entities/Auditing/IModificationAudited.cs @@ -1,27 +1,26 @@ -namespace Genocs.Core.Domain.Entities.Auditing +namespace Genocs.Core.Domain.Entities.Auditing; + +/// +/// This interface is implemented by entities that is wanted to store modification information (who and when modified lastly). +/// Properties are automatically set when updating the . +/// +public interface IModificationAudited : IHasModificationTime { /// - /// This interface is implemented by entities that is wanted to store modification information (who and when modified lastly). - /// Properties are automatically set when updating the . + /// Last modifier user for this entity. /// - public interface IModificationAudited : IHasModificationTime - { - /// - /// Last modifier user for this entity. - /// - long? LastModifierUserId { get; set; } - } + long? UpdatedBy { get; set; } +} +/// +/// Adds navigation properties to interface for user. +/// +/// Type of the user +public interface IModificationAudited : IModificationAudited + where TUser : IEntity +{ /// - /// Adds navigation properties to interface for user. + /// Reference to the last modifier user of this entity. /// - /// Type of the user - public interface IModificationAudited : IModificationAudited - where TUser : IEntity - { - /// - /// Reference to the last modifier user of this entity. - /// - TUser LastModifierUser { get; set; } - } + TUser? UpdatedByUser { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/Entity.cs b/src/Genocs.Core/Domain/Entities/Entity.cs index 24b3b392..3dd43e58 100644 --- a/src/Genocs.Core/Domain/Entities/Entity.cs +++ b/src/Genocs.Core/Domain/Entities/Entity.cs @@ -6,7 +6,7 @@ namespace Genocs.Core.Domain.Entities; /// A shortcut of for most used primary key type (). /// [Serializable] -public abstract class Entity : Entity, IEntity +public abstract class Entity : Entity { } @@ -22,7 +22,7 @@ public abstract class Entity : IEntity /// /// Unique identifier for this entity. /// - public virtual TPrimaryKey Id { get; set; } + public virtual TPrimaryKey Id { get; set; } = default!; /// /// Checks if this entity is transient (it has not an Id). @@ -52,7 +52,7 @@ public virtual bool IsTransient() /// public override bool Equals(object? obj) { - if (obj == null || !(obj is Entity)) + if (obj == null || obj is not Entity) { return false; } @@ -91,7 +91,7 @@ public override bool Equals(object? obj) return false; } */ - return Id.Equals(other.Id); + return Id!.Equals(other.Id); } /// diff --git a/src/Genocs.Core/Domain/Entities/EntityExtensions.cs b/src/Genocs.Core/Domain/Entities/EntityExtensions.cs index ac7868d7..f085e29d 100644 --- a/src/Genocs.Core/Domain/Entities/EntityExtensions.cs +++ b/src/Genocs.Core/Domain/Entities/EntityExtensions.cs @@ -26,8 +26,8 @@ public static void UnDelete(this ISoftDelete entity) if (entity is IDeletionAudited) { var deletionAuditedEntity = entity.As(); - deletionAuditedEntity.DeletionTime = null; - deletionAuditedEntity.DeleterUserId = null; + deletionAuditedEntity.DeletedAt = null; + deletionAuditedEntity.DeletedBy = null; } } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/IAggregateRoot.cs b/src/Genocs.Core/Domain/Entities/IAggregateRoot.cs index 9560df82..0150eeff 100644 --- a/src/Genocs.Core/Domain/Entities/IAggregateRoot.cs +++ b/src/Genocs.Core/Domain/Entities/IAggregateRoot.cs @@ -3,12 +3,12 @@ namespace Genocs.Core.Domain.Entities; -public interface IAggregateRoot : IAggregateRoot, IEntity +public interface IAggregateRoot : IEntity { } -public interface IAggregateRoot : IEntity/*, IGeneratesDomainEvents */ +public interface IAggregateRoot : IEntity, IAggregateRoot/*, IGeneratesDomainEvents */ { } diff --git a/src/Genocs.Core/Domain/Entities/IEntity.cs b/src/Genocs.Core/Domain/Entities/IEntity.cs index 2ef39bb1..2403716f 100644 --- a/src/Genocs.Core/Domain/Entities/IEntity.cs +++ b/src/Genocs.Core/Domain/Entities/IEntity.cs @@ -1,11 +1,14 @@ -using Genocs.Common.Types; - namespace Genocs.Core.Domain.Entities; /// -/// A shortcut of for most used primary key type (). +/// The base interface for all entities. /// -public interface IEntity : IIdentifiable +public interface IEntity { + /// + /// Checks if this entity is transient (not persisted to database) />). + /// + /// True, if this entity is transient, otherwise false. + bool IsTransient(); } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Entities/IEntityOfTPrimaryKey.cs b/src/Genocs.Core/Domain/Entities/IEntityOfTPrimaryKey.cs index 7734b233..07863ce8 100644 --- a/src/Genocs.Core/Domain/Entities/IEntityOfTPrimaryKey.cs +++ b/src/Genocs.Core/Domain/Entities/IEntityOfTPrimaryKey.cs @@ -1,13 +1,11 @@ -namespace Genocs.Core.Domain.Entities; +using Genocs.Common.Types; + +namespace Genocs.Core.Domain.Entities; /// /// Defines interface for base entity type. All the domain object must implement this interface. /// -/// Type of the primary key of the entity. -public interface IEntity +/// Type of the primary key of the entity. +public interface IEntity : IEntity, IIdentifiable { - /// - /// Unique identifier for this entity. - /// - TPrimaryKey Id { get; set; } } diff --git a/src/Genocs.Core/Domain/Repositories/AutoRepositoryTypesAttribute.cs b/src/Genocs.Core/Domain/Repositories/AutoRepositoryTypesAttribute.cs index f1734ebd..5b28b5a3 100644 --- a/src/Genocs.Core/Domain/Repositories/AutoRepositoryTypesAttribute.cs +++ b/src/Genocs.Core/Domain/Repositories/AutoRepositoryTypesAttribute.cs @@ -1,32 +1,31 @@ -namespace Genocs.Core.Domain.Repositories +namespace Genocs.Core.Domain.Repositories; + +/// +/// Used to define auto-repository types for entities. +/// This can be used for DbContext types. +/// +[AttributeUsage(AttributeTargets.Class)] +public class AutoRepositoryTypesAttribute : Attribute { - /// - /// Used to define auto-repository types for entities. - /// This can be used for DbContext types. - /// - [AttributeUsage(AttributeTargets.Class)] - public class AutoRepositoryTypesAttribute : Attribute - { - public Type RepositoryInterface { get; } + public Type RepositoryInterface { get; } - public Type RepositoryInterfaceWithPrimaryKey { get; } + public Type RepositoryInterfaceWithPrimaryKey { get; } - public Type RepositoryImplementation { get; } + public Type RepositoryImplementation { get; } - public Type RepositoryImplementationWithPrimaryKey { get; } + public Type RepositoryImplementationWithPrimaryKey { get; } - public bool WithDefaultRepositoryInterfaces { get; set; } + public bool WithDefaultRepositoryInterfaces { get; set; } - public AutoRepositoryTypesAttribute( - Type repositoryInterface, - Type repositoryInterfaceWithPrimaryKey, - Type repositoryImplementation, - Type repositoryImplementationWithPrimaryKey) - { - RepositoryInterface = repositoryInterface; - RepositoryInterfaceWithPrimaryKey = repositoryInterfaceWithPrimaryKey; - RepositoryImplementation = repositoryImplementation; - RepositoryImplementationWithPrimaryKey = repositoryImplementationWithPrimaryKey; - } + public AutoRepositoryTypesAttribute( + Type repositoryInterface, + Type repositoryInterfaceWithPrimaryKey, + Type repositoryImplementation, + Type repositoryImplementationWithPrimaryKey) + { + RepositoryInterface = repositoryInterface; + RepositoryInterfaceWithPrimaryKey = repositoryInterfaceWithPrimaryKey; + RepositoryImplementation = repositoryImplementation; + RepositoryImplementationWithPrimaryKey = repositoryImplementationWithPrimaryKey; } } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Repositories/IRepository.cs b/src/Genocs.Core/Domain/Repositories/IRepository.cs index fb265b43..b7232eca 100644 --- a/src/Genocs.Core/Domain/Repositories/IRepository.cs +++ b/src/Genocs.Core/Domain/Repositories/IRepository.cs @@ -1,4 +1,4 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; namespace Genocs.Core.Domain.Repositories; @@ -6,8 +6,8 @@ namespace Genocs.Core.Domain.Repositories; /// This interface is used to identify a repository so can be used to be registered by convention. /// Implement generic version instead of this one. /// -public interface IRepository - where TEntity : IIdentifiable +public interface IRepository + where TEntity : IEntity { } \ No newline at end of file diff --git a/src/Genocs.Core/Domain/Repositories/IRepositoryOfTEntityAndTPrimaryKey.cs b/src/Genocs.Core/Domain/Repositories/IRepositoryOfTEntityAndTPrimaryKey.cs index 3ebe15a4..59774660 100644 --- a/src/Genocs.Core/Domain/Repositories/IRepositoryOfTEntityAndTPrimaryKey.cs +++ b/src/Genocs.Core/Domain/Repositories/IRepositoryOfTEntityAndTPrimaryKey.cs @@ -1,4 +1,4 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; using System.Linq.Expressions; namespace Genocs.Core.Domain.Repositories; @@ -7,9 +7,9 @@ namespace Genocs.Core.Domain.Repositories; /// This interface is implemented by all repositories to ensure implementation of fixed methods. /// /// Main Entity type this repository works on. -/// Primary key type of the entity. -public interface IRepositoryOfEntity : IRepository - where TEntity : IIdentifiable +/// Primary key type of the entity. +public interface IRepositoryOfEntity : IRepository + where TEntity : IEntity { #region Select/Get/Query @@ -67,14 +67,14 @@ public interface IRepositoryOfEntity : IRepository /// Primary key of the entity to get. /// Entity. - TEntity Get(TIdentifiable id); + TEntity Get(TKey id); /// /// Gets an entity with given primary key. /// /// Primary key of the entity to get. /// Entity. - Task GetAsync(TIdentifiable id); + Task GetAsync(TKey id); /// /// Gets exactly one entity with given predicate. @@ -95,14 +95,14 @@ public interface IRepositoryOfEntity : IRepository /// Primary key of the entity to get. /// Entity or null. - TEntity? FirstOrDefault(TIdentifiable id); + TEntity? FirstOrDefault(TKey id); /// /// Gets an entity with given primary key or null if not found. /// /// Primary key of the entity to get. /// Entity or null. - Task FirstOrDefaultAsync(TIdentifiable id); + Task FirstOrDefaultAsync(TKey id); /// /// Gets an entity with given predicate or null if not found. @@ -121,7 +121,7 @@ public interface IRepositoryOfEntity : IRepository /// Primary key of the entity to load. /// Entity. - TEntity? Load(TIdentifiable id); + TEntity? Load(TKey id); #endregion @@ -146,7 +146,7 @@ public interface IRepositoryOfEntity : IRepository /// Entity. /// Id of the entity. - TIdentifiable InsertAndGetId(TEntity entity); + TKey InsertAndGetId(TEntity entity); /// /// Inserts a new entity and gets it's Id. @@ -155,7 +155,7 @@ public interface IRepositoryOfEntity : IRepository /// Entity. /// Id of the entity. - Task InsertAndGetIdAsync(TEntity entity); + Task InsertAndGetIdAsync(TEntity entity); /// /// Inserts or updates given entity depending on Id's value. @@ -177,7 +177,7 @@ public interface IRepositoryOfEntity : IRepository /// Entity. /// Id of the entity. - TIdentifiable InsertOrUpdateAndGetId(TEntity entity); + TKey InsertOrUpdateAndGetId(TEntity entity); /// /// Inserts or updates given entity depending on Id's value. @@ -187,7 +187,7 @@ public interface IRepositoryOfEntity : IRepository /// Entity. /// Id of the entity. - Task InsertOrUpdateAndGetIdAsync(TEntity entity); + Task InsertOrUpdateAndGetIdAsync(TEntity entity); #endregion @@ -211,7 +211,7 @@ public interface IRepositoryOfEntity : IRepositoryId of the entity. /// Action that can be used to change values of the entity. /// Updated entity. - TEntity Update(TIdentifiable id, Action updateAction); + TEntity Update(TKey id, Action updateAction); /// /// Updates an existing entity. @@ -219,7 +219,7 @@ public interface IRepositoryOfEntity : IRepositoryId of the entity. /// Action that can be used to change values of the entity. /// Updated entity. - Task UpdateAsync(TIdentifiable id, Func updateAction); + Task UpdateAsync(TKey id, Func updateAction); #endregion @@ -241,13 +241,13 @@ public interface IRepositoryOfEntity : IRepository /// Primary key of the entity. - void Delete(TIdentifiable id); + void Delete(TKey id); /// /// Deletes an entity by primary key. /// /// Primary key of the entity. - Task DeleteAsync(TIdentifiable id); + Task DeleteAsync(TKey id); /// /// Deletes many entities by function. diff --git a/src/Genocs.Core/Domain/Repositories/RepositoryBase.cs b/src/Genocs.Core/Domain/Repositories/RepositoryBase.cs index 58e998a2..ce2d7c3b 100644 --- a/src/Genocs.Core/Domain/Repositories/RepositoryBase.cs +++ b/src/Genocs.Core/Domain/Repositories/RepositoryBase.cs @@ -1,6 +1,5 @@ -using System.Linq.Expressions; -using Genocs.Common.Types; using Genocs.Core.Domain.Entities; +using System.Linq.Expressions; // using Genocs.Core.Dependency; // using Genocs.Core.Domain.Uow; @@ -10,13 +9,13 @@ namespace Genocs.Core.Domain.Repositories; /// -/// Base class to implement . +/// Base class to implement . /// It implements some methods in most simple way. /// /// Type of the Entity for this repository. -/// Type of the Primary Key for this repository. -public abstract class RepositoryBase : IRepository/*, IUnitOfWorkManagerAccessor */ - where TEntity : class, IIdentifiable +/// Type of the Primary Key for this repository. +public abstract class RepositoryBase : IRepository/*, IUnitOfWorkManagerAccessor */ + where TEntity : IEntity { /// /// The multi tenancy side. @@ -70,26 +69,16 @@ public virtual T Query(Func, T> queryMethod) return queryMethod(GetAll()); } - public virtual TEntity Get(TPrimaryKey id) + public virtual TEntity Get(TKey id) { var entity = FirstOrDefault(id); - if (entity == null) - { - throw new EntityNotFoundException(typeof(TEntity), id); - } - - return entity; + return entity ?? throw new EntityNotFoundException(typeof(TEntity), id); } - public virtual async Task GetAsync(TPrimaryKey id) + public virtual async Task GetAsync(TKey id) { var entity = await FirstOrDefaultAsync(id); - if (entity == null) - { - throw new EntityNotFoundException(typeof(TEntity), id); - } - - return entity; + return entity ?? throw new EntityNotFoundException(typeof(TEntity), id); } public virtual TEntity Single(Expression> predicate) @@ -102,12 +91,12 @@ public virtual Task SingleAsync(Expression> predica return Task.FromResult(Single(predicate)); } - public virtual TEntity? FirstOrDefault(TPrimaryKey id) + public virtual TEntity? FirstOrDefault(TKey id) { return GetAll().FirstOrDefault(CreateEqualityExpressionForId(id)); } - public virtual Task FirstOrDefaultAsync(TPrimaryKey id) + public virtual Task FirstOrDefaultAsync(TKey id) { return Task.FromResult(FirstOrDefault(id)); } @@ -122,7 +111,7 @@ public virtual Task SingleAsync(Expression> predica return Task.FromResult(FirstOrDefault(predicate)); } - public virtual TEntity Load(TPrimaryKey id) + public virtual TEntity Load(TKey id) { return Get(id); } @@ -134,12 +123,12 @@ public virtual Task InsertAsync(TEntity entity) return Task.FromResult(Insert(entity)); } - public virtual TPrimaryKey InsertAndGetId(TEntity entity) + public virtual TKey InsertAndGetId(TEntity entity) { return Insert(entity).Id; } - public virtual Task InsertAndGetIdAsync(TEntity entity) + public virtual Task InsertAndGetIdAsync(TEntity entity) { return Task.FromResult(InsertAndGetId(entity)); } @@ -158,12 +147,12 @@ public virtual async Task InsertOrUpdateAsync(TEntity entity) : await UpdateAsync(entity); } - public virtual TPrimaryKey InsertOrUpdateAndGetId(TEntity entity) + public virtual TKey InsertOrUpdateAndGetId(TEntity entity) { return InsertOrUpdate(entity).Id; } - public virtual Task InsertOrUpdateAndGetIdAsync(TEntity entity) + public virtual Task InsertOrUpdateAndGetIdAsync(TEntity entity) { return Task.FromResult(InsertOrUpdateAndGetId(entity)); } @@ -175,14 +164,14 @@ public virtual Task UpdateAsync(TEntity entity) return Task.FromResult(Update(entity)); } - public virtual TEntity Update(TPrimaryKey id, Action updateAction) + public virtual TEntity Update(TKey id, Action updateAction) { var entity = Get(id); updateAction(entity); return entity; } - public virtual async Task UpdateAsync(TPrimaryKey id, Func updateAction) + public virtual async Task UpdateAsync(TKey id, Func updateAction) { var entity = await GetAsync(id); await updateAction(entity); @@ -197,9 +186,9 @@ public virtual Task DeleteAsync(TEntity entity) return Task.FromResult(0); } - public abstract void Delete(TPrimaryKey id); + public abstract void Delete(TKey id); - public virtual Task DeleteAsync(TPrimaryKey id) + public virtual Task DeleteAsync(TKey id) { Delete(id); return Task.FromResult(0); @@ -259,13 +248,13 @@ public virtual Task LongCountAsync(Expression> predica return Task.FromResult(LongCount(predicate)); } - protected virtual Expression> CreateEqualityExpressionForId(TPrimaryKey id) + protected virtual Expression> CreateEqualityExpressionForId(TKey id) { var lambdaParam = Expression.Parameter(typeof(TEntity)); var lambdaBody = Expression.Equal( Expression.PropertyOrField(lambdaParam, "Id"), - Expression.Constant(id, typeof(TPrimaryKey))); + Expression.Constant(id, typeof(TKey))); return Expression.Lambda>(lambdaBody, lambdaParam); } diff --git a/src/Genocs.Core/Extensions/ObjectExtensions.cs b/src/Genocs.Core/Extensions/ObjectExtensions.cs index 518d32f5..c6656ba7 100644 --- a/src/Genocs.Core/Extensions/ObjectExtensions.cs +++ b/src/Genocs.Core/Extensions/ObjectExtensions.cs @@ -21,11 +21,11 @@ public static T As(this object obj) } /// - /// Converts given object to a value type using method. + /// Converts given object to a value type using method. /// /// Object to be converted. /// Type of the target object. - /// Converted object + /// Converted object. public static T To(this object obj) where T : struct { diff --git a/src/Genocs.Core/Genocs.Core.csproj b/src/Genocs.Core/Genocs.Core.csproj index 2042c094..32e880bc 100644 --- a/src/Genocs.Core/Genocs.Core.csproj +++ b/src/Genocs.Core/Genocs.Core.csproj @@ -22,12 +22,12 @@ - + - + diff --git a/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj b/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj index 39fe5750..fc01345c 100644 --- a/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj +++ b/src/Genocs.Discovery.Consul/Genocs.Discovery.Consul.csproj @@ -24,8 +24,8 @@ - - + + diff --git a/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj b/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj index a0a2dead..1110507f 100644 --- a/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj +++ b/src/Genocs.HTTP.RestEase/Genocs.HTTP.RestEase.csproj @@ -25,10 +25,10 @@ - - - - + + + + diff --git a/src/Genocs.HTTP/Genocs.HTTP.csproj b/src/Genocs.HTTP/Genocs.HTTP.csproj index 4ed79a9a..f7aa5933 100644 --- a/src/Genocs.HTTP/Genocs.HTTP.csproj +++ b/src/Genocs.HTTP/Genocs.HTTP.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.HTTP/GenocsLoggingScopeHttpMessageHandler.cs b/src/Genocs.HTTP/GenocsLoggingScopeHttpMessageHandler.cs index 0753c680..468ab49d 100644 --- a/src/Genocs.HTTP/GenocsLoggingScopeHttpMessageHandler.cs +++ b/src/Genocs.HTTP/GenocsLoggingScopeHttpMessageHandler.cs @@ -88,6 +88,12 @@ public static void RequestPipelineEnd(ILogger logger, HttpResponseMessage respon } string? requestUri = uri?.OriginalString; + + if (string.IsNullOrWhiteSpace(requestUri)) + { + return uri; + } + bool hasMatch = false; foreach (string part in maskedRequestUrlParts) { diff --git a/src/Genocs.HTTP/ICorrelationIdFactory.cs b/src/Genocs.HTTP/ICorrelationIdFactory.cs index 4580c4dc..099e8075 100644 --- a/src/Genocs.HTTP/ICorrelationIdFactory.cs +++ b/src/Genocs.HTTP/ICorrelationIdFactory.cs @@ -9,5 +9,5 @@ public interface ICorrelationIdFactory /// Create a correlationId. /// /// - string Create(); + string? Create(); } \ No newline at end of file diff --git a/src/Genocs.HTTP/SystemTextJsonHttpClientSerializer.cs b/src/Genocs.HTTP/SystemTextJsonHttpClientSerializer.cs index accab9d4..82e5e522 100644 --- a/src/Genocs.HTTP/SystemTextJsonHttpClientSerializer.cs +++ b/src/Genocs.HTTP/SystemTextJsonHttpClientSerializer.cs @@ -9,6 +9,7 @@ public class SystemTextJsonHttpClientSerializer : IHttpClientSerializer public SystemTextJsonHttpClientSerializer(JsonSerializerOptions? options = null) { + // Default options _options = options ?? new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, @@ -18,7 +19,9 @@ public SystemTextJsonHttpClientSerializer(JsonSerializerOptions? options = null) }; } - public string Serialize(T value) => JsonSerializer.Serialize(value, _options); + public string Serialize(T value) + => JsonSerializer.Serialize(value, _options); - public ValueTask DeserializeAsync(Stream stream) => JsonSerializer.DeserializeAsync(stream, _options); + public ValueTask DeserializeAsync(Stream stream) + => JsonSerializer.DeserializeAsync(stream, _options); } \ No newline at end of file diff --git a/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj b/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj index 937864a2..0f2c4d4b 100644 --- a/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj +++ b/src/Genocs.LoadBalancing.Fabio/Genocs.LoadBalancing.Fabio.csproj @@ -24,9 +24,9 @@ - - - + + + diff --git a/src/Genocs.Logging/CQRS/HandlerLogTemplate.cs b/src/Genocs.Logging/CQRS/HandlerLogTemplate.cs index 12ac2957..757cab15 100644 --- a/src/Genocs.Logging/CQRS/HandlerLogTemplate.cs +++ b/src/Genocs.Logging/CQRS/HandlerLogTemplate.cs @@ -15,6 +15,6 @@ public sealed class HandlerLogTemplate return null; } - return OnError.TryGetValue(exceptionType, out var template) ? template : null; + return OnError.TryGetValue(exceptionType, out string? template) ? template : null; } } \ No newline at end of file diff --git a/src/Genocs.Logging/CQRS/IMessageToLogTemplateMapper.cs b/src/Genocs.Logging/CQRS/IMessageToLogTemplateMapper.cs index 8785149a..cb71eb87 100644 --- a/src/Genocs.Logging/CQRS/IMessageToLogTemplateMapper.cs +++ b/src/Genocs.Logging/CQRS/IMessageToLogTemplateMapper.cs @@ -1,15 +1,16 @@ namespace Genocs.Logging.CQRS; /// -/// Interface used to log messages using a template +/// Interface used to log messages using a template. /// public interface IMessageToLogTemplateMapper { /// - /// Map the message using the template + /// Map the message using the template. /// - /// The type of the message - /// The message instance - /// The LogTemplate - HandlerLogTemplate? Map(TMessage message) where TMessage : class; + /// The type of the message. + /// The message instance. + /// The LogTemplate. + HandlerLogTemplate? Map(TMessage message) + where TMessage : class; } \ No newline at end of file diff --git a/src/Genocs.Logging/Configurations/SeqOptions.cs b/src/Genocs.Logging/Configurations/SeqOptions.cs index 7fc4a973..7e20ccb1 100644 --- a/src/Genocs.Logging/Configurations/SeqOptions.cs +++ b/src/Genocs.Logging/Configurations/SeqOptions.cs @@ -1,8 +1,22 @@ namespace Genocs.Logging.Configurations; +/// +/// Seq Settings. +/// public class SeqOptions { + /// + /// It define whether the Seq logger and tracing are enabled or not. + /// public bool Enabled { get; set; } + + /// + /// The Seq Url. + /// public string? Url { get; set; } + + /// + /// The Seq ApiKey. + /// public string? ApiKey { get; set; } } \ No newline at end of file diff --git a/src/Genocs.Logging/Genocs.Logging.csproj b/src/Genocs.Logging/Genocs.Logging.csproj index 8d2f616e..68b271d5 100644 --- a/src/Genocs.Logging/Genocs.Logging.csproj +++ b/src/Genocs.Logging/Genocs.Logging.csproj @@ -22,7 +22,7 @@ - + @@ -36,7 +36,7 @@ - + diff --git a/src/Genocs.MessageBrokers.Outbox.MongoDB/Extensions.cs b/src/Genocs.MessageBrokers.Outbox.MongoDB/Extensions.cs index 4206a9c3..b59a4a51 100644 --- a/src/Genocs.MessageBrokers.Outbox.MongoDB/Extensions.cs +++ b/src/Genocs.MessageBrokers.Outbox.MongoDB/Extensions.cs @@ -13,11 +13,11 @@ public static IMessageOutboxConfigurator AddMongo(this IMessageOutboxConfigurato var builder = configurator.Builder; var options = configurator.Options; - var inboxCollection = string.IsNullOrWhiteSpace(options.InboxCollection) + string inboxCollection = string.IsNullOrWhiteSpace(options.InboxCollection) ? "inbox" : options.InboxCollection; - var outboxCollection = string.IsNullOrWhiteSpace(options.OutboxCollection) + string outboxCollection = string.IsNullOrWhiteSpace(options.OutboxCollection) ? "outbox" : options.OutboxCollection; diff --git a/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj b/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj index 8ea31f0b..55003bab 100644 --- a/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj +++ b/src/Genocs.MessageBrokers.Outbox.MongoDB/Genocs.MessageBrokers.Outbox.MongoDB.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoMessageOutbox.cs b/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoMessageOutbox.cs index f6a04267..cc3c8bd3 100644 --- a/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoMessageOutbox.cs +++ b/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoMessageOutbox.cs @@ -1,7 +1,7 @@ using Genocs.MessageBrokers.Outbox.Configurations; using Genocs.MessageBrokers.Outbox.Messages; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Genocs.Persistence.MongoDb.Repositories; -using Genocs.Persistence.MongoDb.Repositories.Mentor; using Microsoft.Extensions.Logging; using MongoDB.Driver; using System.Text.Json; @@ -22,17 +22,19 @@ internal sealed class MongoMessageOutbox : IMessageOutbox, IMessageOutboxAccesso }; private readonly IMongoSessionFactory _sessionFactory; - private readonly IMongoRepository _inboxRepository; - private readonly IMongoRepository _outboxRepository; + private readonly IMongoDbBaseRepository _inboxRepository; + private readonly IMongoDbBaseRepository _outboxRepository; private readonly ILogger _logger; private readonly bool _transactionsEnabled; public bool Enabled { get; } - public MongoMessageOutbox(IMongoSessionFactory sessionFactory, - IMongoRepository inboxRepository, - IMongoRepository outboxRepository, - OutboxOptions options, ILogger logger) + public MongoMessageOutbox( + IMongoSessionFactory sessionFactory, + IMongoDbBaseRepository inboxRepository, + IMongoDbBaseRepository outboxRepository, + OutboxOptions options, + ILogger logger) { _sessionFactory = sessionFactory; _inboxRepository = inboxRepository; @@ -102,9 +104,15 @@ await _inboxRepository.AddAsync(new InboxMessage } } - public async Task SendAsync(T message, string originatedMessageId = null, string messageId = null, - string correlationId = null, string spanContext = null, object messageContext = null, - IDictionary headers = null) where T : class + public async Task SendAsync( + T message, + string? originatedMessageId = null, + string? messageId = null, + string? correlationId = null, + string? spanContext = null, + object? messageContext = null, + IDictionary? headers = null) + where T : class { if (!Enabled) { diff --git a/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoOutboxInitializer.cs b/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoOutboxInitializer.cs index d7ba1050..ea69c74b 100644 --- a/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoOutboxInitializer.cs +++ b/src/Genocs.MessageBrokers.Outbox.MongoDB/Internals/MongoOutboxInitializer.cs @@ -35,11 +35,13 @@ public async Task InitializeAsync() var inboxBuilder = Builders.IndexKeys; await _database.GetCollection(inboxCollection) .Indexes.CreateOneAsync( - new CreateIndexModel(inboxBuilder.Ascending(i => i.ProcessedAt), - new CreateIndexOptions - { - ExpireAfter = TimeSpan.FromSeconds(_options.Expiry) - })); + new CreateIndexModel( + inboxBuilder.Ascending(i => i.ProcessedAt), + new CreateIndexOptions + { + ExpireAfter = TimeSpan.FromSeconds(_options.Expiry) + }) + ); string outboxCollection = string.IsNullOrWhiteSpace(_options.OutboxCollection) ? "outbox" @@ -48,10 +50,11 @@ await _database.GetCollection(inboxCollection) var outboxBuilder = Builders.IndexKeys; await _database.GetCollection(outboxCollection) .Indexes.CreateOneAsync( - new CreateIndexModel(outboxBuilder.Ascending(i => i.ProcessedAt), - new CreateIndexOptions - { - ExpireAfter = TimeSpan.FromSeconds(_options.Expiry) - })); + new CreateIndexModel( + outboxBuilder.Ascending(i => i.ProcessedAt), + new CreateIndexOptions + { + ExpireAfter = TimeSpan.FromSeconds(_options.Expiry) + })); } } \ No newline at end of file diff --git a/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj b/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj index 38920888..40a7ffe0 100644 --- a/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj +++ b/src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.MessageBrokers.Outbox/Messages/InboxMessage.cs b/src/Genocs.MessageBrokers.Outbox/Messages/InboxMessage.cs index 8ffc774f..93402645 100644 --- a/src/Genocs.MessageBrokers.Outbox/Messages/InboxMessage.cs +++ b/src/Genocs.MessageBrokers.Outbox/Messages/InboxMessage.cs @@ -1,8 +1,8 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; namespace Genocs.MessageBrokers.Outbox.Messages; -public sealed class InboxMessage : IIdentifiable +public sealed class InboxMessage : IEntity { public string Id { get; set; } public DateTime ProcessedAt { get; set; } diff --git a/src/Genocs.MessageBrokers.Outbox/Messages/OutboxMessage.cs b/src/Genocs.MessageBrokers.Outbox/Messages/OutboxMessage.cs index 6c4ce817..f557f795 100644 --- a/src/Genocs.MessageBrokers.Outbox/Messages/OutboxMessage.cs +++ b/src/Genocs.MessageBrokers.Outbox/Messages/OutboxMessage.cs @@ -1,20 +1,20 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; namespace Genocs.MessageBrokers.Outbox.Messages; -public sealed class OutboxMessage : IIdentifiable +public sealed class OutboxMessage : IEntity { public string Id { get; set; } public string? OriginatedMessageId { get; set; } public string? CorrelationId { get; set; } public string? SpanContext { get; set; } public Dictionary Headers { get; set; } = new(); - public string MessageType { get; set; } - public string MessageContextType { get; set; } + public string? MessageType { get; set; } + public string? MessageContextType { get; set; } public object? Message { get; set; } public object? MessageContext { get; set; } - public string SerializedMessage { get; set; } - public string SerializedMessageContext { get; set; } + public string? SerializedMessage { get; set; } + public string? SerializedMessageContext { get; set; } public DateTime SentAt { get; set; } public DateTime? ProcessedAt { get; set; } diff --git a/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj b/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj index a1fb3ace..7ebfcf64 100644 --- a/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj +++ b/src/Genocs.MessageBrokers.RabbitMQ/Genocs.MessageBrokers.RabbitMQ.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj b/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj index 8cf8d174..8cb7ec2c 100644 --- a/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj +++ b/src/Genocs.MessageBrokers/Genocs.MessageBrokers.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Metrics/Genocs.Metrics.csproj b/src/Genocs.Metrics/Genocs.Metrics.csproj index af281ff6..fa0e7a00 100644 --- a/src/Genocs.Metrics/Genocs.Metrics.csproj +++ b/src/Genocs.Metrics/Genocs.Metrics.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Monitoring/Genocs.Monitoring.csproj b/src/Genocs.Monitoring/Genocs.Monitoring.csproj index b54034ff..0d5d7ff6 100644 --- a/src/Genocs.Monitoring/Genocs.Monitoring.csproj +++ b/src/Genocs.Monitoring/Genocs.Monitoring.csproj @@ -40,9 +40,9 @@ - - - + + + diff --git a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj index 4e91b225..b564f04d 100644 --- a/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj +++ b/src/Genocs.Persistence.MongoDb.UnitTests/Genocs.Persistence.MongoDB.UnitTests.csproj @@ -24,7 +24,7 @@ - + diff --git a/src/Genocs.Persistence.MongoDb/Domain/Entities/IMongoDbEntity.cs b/src/Genocs.Persistence.MongoDb/Domain/Entities/IMongoDbEntity.cs new file mode 100644 index 00000000..0f38ca67 --- /dev/null +++ b/src/Genocs.Persistence.MongoDb/Domain/Entities/IMongoDbEntity.cs @@ -0,0 +1,12 @@ +using Genocs.Core.Domain.Entities; +using MongoDB.Bson; + +namespace Genocs.Persistence.MongoDb.Domain.Entities; + +/// +/// Default MongoDB entity. +/// +public interface IMongoDbEntity : IEntity +{ + +} diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Mentor/IMongoRepository.cs b/src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbBaseRepository.cs similarity index 76% rename from src/Genocs.Persistence.MongoDb/Repositories/Mentor/IMongoRepository.cs rename to src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbBaseRepository.cs index 16cf0ddf..5cdacef2 100644 --- a/src/Genocs.Persistence.MongoDb/Repositories/Mentor/IMongoRepository.cs +++ b/src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbBaseRepository.cs @@ -1,14 +1,14 @@ -using Genocs.Common.Types; +using System.Linq.Expressions; using Genocs.Core.CQRS.Queries; +using Genocs.Core.Domain.Entities; using Genocs.Core.Domain.Repositories; using MongoDB.Driver; using MongoDB.Driver.Linq; -using System.Linq.Expressions; -namespace Genocs.Persistence.MongoDb.Repositories.Mentor; +namespace Genocs.Persistence.MongoDb.Domain.Repositories; -public interface IMongoRepository : IRepositoryOfEntity - where TEntity : IIdentifiable +public interface IMongoDbBaseRepository : IRepositoryOfEntity + where TEntity : IEntity { IMongoCollection Collection { get; } diff --git a/src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbRepository.cs b/src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbRepository.cs new file mode 100644 index 00000000..c8ff528f --- /dev/null +++ b/src/Genocs.Persistence.MongoDb/Domain/Repositories/IMongoDbRepository.cs @@ -0,0 +1,15 @@ +using Genocs.Persistence.MongoDb.Domain.Entities; +using MongoDB.Bson; + +namespace Genocs.Persistence.MongoDb.Domain.Repositories; + +/// +/// The MongoDb repository interface. +/// This interface is used to define the contract for the MongoDb repositories when the entity has an ObjectId as the primary key. +/// +/// The type of the entity. +public interface IMongoDbRepository : IMongoDbBaseRepository + where TEntity : IMongoDbEntity +{ + +} diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Mentor/MongoRepository.cs b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepository.cs similarity index 84% rename from src/Genocs.Persistence.MongoDb/Repositories/Mentor/MongoRepository.cs rename to src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepository.cs index 3bee0d81..d7f91e79 100644 --- a/src/Genocs.Persistence.MongoDb/Repositories/Mentor/MongoRepository.cs +++ b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepository.cs @@ -1,16 +1,17 @@ -using Genocs.Common.Types; using Genocs.Core.CQRS.Queries; +using Genocs.Core.Domain.Entities; using Genocs.Core.Domain.Repositories; +using Genocs.Persistence.MongoDb.Repositories; using MongoDB.Driver; using MongoDB.Driver.Linq; using System.Linq.Expressions; -namespace Genocs.Persistence.MongoDb.Repositories.Mentor; +namespace Genocs.Persistence.MongoDb.Domain.Repositories; -internal class MongoRepository : IMongoRepository - where TEntity : IIdentifiable +internal class MongoDbBaseRepository : IMongoDbBaseRepository + where TEntity : IEntity { - public MongoRepository(IMongoDatabase database, string collectionName) + public MongoDbBaseRepository(IMongoDatabase database, string collectionName) { Collection = database.GetCollection(collectionName); } @@ -26,7 +27,7 @@ public IMongoQueryable GetMongoQueryable() return Collection.AsQueryable(); } - public Task GetAsync(TIdentifiable id) + public Task GetAsync(TKey id) => GetAsync(e => e.Id.Equals(id)); public Task GetAsync(Expression> predicate) @@ -69,7 +70,7 @@ public Task UpdateAsync(TEntity entity, Expression> predicat /// /// /// - public Task DeleteAsync(TIdentifiable id) + public Task DeleteAsync(TKey id) => DeleteAsync(e => e.Id.Equals(id)); public Task DeleteAsync(Expression> predicate) @@ -115,7 +116,7 @@ public T Query(Func, T> queryMethod) throw new NotImplementedException(); } - public TEntity Get(TIdentifiable id) + public TEntity Get(TKey id) => Collection.Find(c => c.Id.Equals(id)).First(); public TEntity Single(Expression> predicate) @@ -127,10 +128,10 @@ public async Task SingleAsync(Expression> predicate return await result.SingleAsync(); } - public TEntity? FirstOrDefault(TIdentifiable id) + public TEntity? FirstOrDefault(TKey id) => Collection.Find(c => c.Id.Equals(id)).FirstOrDefault(); - public async Task FirstOrDefaultAsync(TIdentifiable id) + public async Task FirstOrDefaultAsync(TKey id) { var result = await Collection.FindAsync(c => c.Id.Equals(id)); return await result.FirstOrDefaultAsync(); @@ -145,7 +146,7 @@ public TEntity FirstOrDefault(Expression> predicate) return await result.FirstOrDefaultAsync(); } - public TEntity? Load(TIdentifiable id) + public TEntity? Load(TKey id) => FirstOrDefault(id); public TEntity Insert(TEntity entity) @@ -160,10 +161,10 @@ public async Task InsertAsync(TEntity entity) return entity; } - public TIdentifiable InsertAndGetId(TEntity entity) + public TKey InsertAndGetId(TEntity entity) => Insert(entity).Id; - public async Task InsertAndGetIdAsync(TEntity entity) + public async Task InsertAndGetIdAsync(TEntity entity) => (await InsertAsync(entity)).Id; public TEntity InsertOrUpdate(TEntity entity) @@ -178,10 +179,10 @@ public async Task InsertOrUpdateAsync(TEntity entity) return entity; } - public TIdentifiable InsertOrUpdateAndGetId(TEntity entity) + public TKey InsertOrUpdateAndGetId(TEntity entity) => InsertOrUpdate(entity).Id; - public async Task InsertOrUpdateAndGetIdAsync(TEntity entity) + public async Task InsertOrUpdateAndGetIdAsync(TEntity entity) => (await InsertOrUpdateAsync(entity)).Id; public TEntity Update(TEntity entity) @@ -190,12 +191,12 @@ public TEntity Update(TEntity entity) return entity; } - public TEntity Update(TIdentifiable id, Action updateAction) + public TEntity Update(TKey id, Action updateAction) { throw new NotImplementedException(); } - public Task UpdateAsync(TIdentifiable id, Func updateAction) + public Task UpdateAsync(TKey id, Func updateAction) { throw new NotImplementedException(); } @@ -216,7 +217,7 @@ public Task DeleteAsync(TEntity entity) return DeleteAsync(entity.Id); } - public void Delete(TIdentifiable id) + public void Delete(TKey id) { if (id == null) { @@ -228,10 +229,7 @@ public void Delete(TIdentifiable id) public void Delete(Expression> predicate) { - if (predicate == null) - { - throw new ArgumentNullException(nameof(predicate)); - } + ArgumentNullException.ThrowIfNull(predicate); Collection.DeleteMany(predicate); } @@ -260,7 +258,7 @@ public long LongCount(Expression> predicate) public async Task LongCountAsync(Expression> predicate) => await Collection.CountDocumentsAsync(predicate); - async Task IRepositoryOfEntity.UpdateAsync(TEntity entity) + async Task IRepositoryOfEntity.UpdateAsync(TEntity entity) { await UpdateAsync(entity, e => e.Id!.Equals(entity.Id)); return entity; diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntityAndKey.cs b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepositoryOfType.cs similarity index 76% rename from src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntityAndKey.cs rename to src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepositoryOfType.cs index 5e44e9ae..e498574a 100644 --- a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntityAndKey.cs +++ b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbBaseRepositoryOfType.cs @@ -1,22 +1,33 @@ -using Genocs.Common.Types; using Genocs.Core.CQRS.Queries; using Genocs.Core.Domain.Entities; using Genocs.Core.Domain.Repositories; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Repositories; using MongoDB.Driver; using MongoDB.Driver.Linq; using System.Linq.Expressions; -namespace Genocs.Persistence.MongoDb.Repositories.Clean; +namespace Genocs.Persistence.MongoDb.Domain.Repositories; /// /// Implements IRepository for MongoDB. /// /// Type of the Entity for this repository. -/// Primary key of the entity. -public class MongoDbRepositoryBase : RepositoryBase, IMongoRepository - where TEntity : class, IIdentifiable +/// Primary key of the entity. +public class MongoDbBaseRepositoryOfType : RepositoryBase, IMongoDbBaseRepository + where TEntity : IEntity { + private readonly IMongoDatabaseProvider _databaseProvider; + protected IMongoCollection? _collection; + + /// + /// Standard constructor. + /// + /// + public MongoDbBaseRepositoryOfType(IMongoDatabaseProvider databaseProvider) + { + _databaseProvider = databaseProvider; + } + /// /// Get the MongoDB database. /// @@ -25,9 +36,6 @@ public virtual IMongoDatabase Database get { return _databaseProvider.Database; } } - private readonly IMongoDatabaseProvider _databaseProvider; - protected IMongoCollection? _collection; - /// /// Get the MongoDB collection from a custom attribute or from the entity name. /// @@ -40,14 +48,17 @@ public virtual IMongoCollection Collection return _collection; } - var attrs = Attribute.GetCustomAttributes(typeof(TEntity)); // Reflection. + Attribute[] attrs = Attribute.GetCustomAttributes(typeof(TEntity)); // Reflection. // Displaying output. foreach (var attr in attrs) { - if (attr is TableMappingAttribute) + if (attr != null) { - return _databaseProvider.Database.GetCollection((attr as TableMappingAttribute).Name); + if ((attr != null) && attr is TableMappingAttribute tmp) + { + return _databaseProvider.Database.GetCollection(tmp.Name); + } } } @@ -57,15 +68,6 @@ public virtual IMongoCollection Collection } } - /// - /// Standard constructor. - /// - /// - public MongoDbRepositoryBase(IMongoDatabaseProvider databaseProvider) - { - _databaseProvider = databaseProvider; - } - /// /// Get all entities as IQueryable. /// @@ -79,24 +81,21 @@ public override IQueryable GetAll() /// /// /// It is thrown if the entity is not found. - public override TEntity Get(TPrimaryKey id) + public override TEntity Get(TKey id) { var filter = Builders.Filter.Eq(m => m.Id, id); var entity = Collection.Find(filter).FirstOrDefault(); - if (entity == null) - { - throw new EntityNotFoundException("There is no such an entity with given primary key. Entity type: " + typeof(TEntity).FullName + ", primary key: " + id); - } - - return entity; + return entity == null + ? throw new EntityNotFoundException("There is no such an entity with given primary key. Entity type: " + typeof(TEntity).FullName + ", primary key: " + id) + : entity; } /// /// First Or Default entity. /// - /// - /// - public override TEntity FirstOrDefault(TPrimaryKey id) + /// The domain objjet id. + /// The entity if found otherwise null. + public override TEntity FirstOrDefault(TKey id) { var filter = Builders.Filter.Eq(m => m.Id, id); return Collection.Find(filter).FirstOrDefault(); @@ -105,8 +104,8 @@ public override TEntity FirstOrDefault(TPrimaryKey id) /// /// Insert an entity. /// - /// - /// + /// The entity to insert. + /// The entity. public override TEntity Insert(TEntity entity) { Collection.InsertOne(entity); @@ -116,8 +115,8 @@ public override TEntity Insert(TEntity entity) /// /// Update an existing entity. /// - /// - /// + /// The entity to insert. + /// The entity. public override TEntity Update(TEntity entity) { Collection.ReplaceOneAsync(filter: g => g.Id.Equals(entity.Id), replacement: entity); @@ -135,7 +134,7 @@ public override void Delete(TEntity entity) /// Delete entity by primary key. /// /// - public override void Delete(TPrimaryKey id) + public override void Delete(TKey id) { var query = Builders.Filter.Eq(m => m.Id, id); var deleteResult = Collection.DeleteOneAsync(query).Result; diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepository.cs b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbRepository.cs similarity index 62% rename from src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepository.cs rename to src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbRepository.cs index 30463760..67f8a26a 100644 --- a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepository.cs +++ b/src/Genocs.Persistence.MongoDb/Domain/Repositories/MongoDbRepository.cs @@ -1,14 +1,14 @@ -using Genocs.Common.Types; +using Genocs.Persistence.MongoDb.Domain.Entities; using MongoDB.Bson; -namespace Genocs.Persistence.MongoDb.Repositories.Clean; +namespace Genocs.Persistence.MongoDb.Domain.Repositories; /// /// Implements IRepository for MongoDB. /// /// Type of the Entity for this repository. -public class MongoDbRepository : MongoDbRepositoryBase, IMongoDbRepository - where TEntity : class, IIdentifiable +public class MongoDbRepository : MongoDbBaseRepositoryOfType, IMongoDbRepository + where TEntity : IMongoDbEntity { /// /// The standard constructor. diff --git a/src/Genocs.Persistence.MongoDb/Encryptions/AzureInitializer.cs b/src/Genocs.Persistence.MongoDb/Encryptions/AzureInitializer.cs index eb5222e5..a9e71c14 100644 --- a/src/Genocs.Persistence.MongoDb/Encryptions/AzureInitializer.cs +++ b/src/Genocs.Persistence.MongoDb/Encryptions/AzureInitializer.cs @@ -60,7 +60,7 @@ DataKeyOptions GetDataKeyOptions(List altNames) { Unique = true, PartialFilterExpression = new BsonDocument - {{"keyAltNames", new BsonDocument {{"$exists", new BsonBoolean(true)}}}} + { { "keyAltNames", new BsonDocument { { "$exists", new BsonBoolean(true) } } } } }; var builder = Builders.IndexKeys; @@ -88,7 +88,6 @@ DataKeyOptions GetDataKeyOptions(List altNames) var dataKeyOptions3 = GetDataKeyOptions(new List { "dataKey3" }); var dataKeyOptions4 = GetDataKeyOptions(new List { "dataKey4" }); - BsonBinaryData CreateKeyGetID(DataKeyOptions options) { var dateKeyGuid = clientEncryption.CreateDataKey(provider, options, CancellationToken.None); @@ -166,7 +165,6 @@ BsonBinaryData CreateKeyGetID(DataKeyOptions options) encryptedFieldsMap: encryptedFieldsMap, extraOptions: extraOptions); - return autoEncryptionOptions; // This is the last client diff --git a/src/Genocs.Persistence.MongoDb/Extensions/MongoDbExtensions.cs b/src/Genocs.Persistence.MongoDb/Extensions/MongoDbExtensions.cs index 06d4b5a4..aa7eea7a 100644 --- a/src/Genocs.Persistence.MongoDb/Extensions/MongoDbExtensions.cs +++ b/src/Genocs.Persistence.MongoDb/Extensions/MongoDbExtensions.cs @@ -1,12 +1,11 @@ -using Genocs.Common.Types; using Genocs.Core.Builders; +using Genocs.Core.Domain.Entities; using Genocs.Persistence.MongoDb.Builders; using Genocs.Persistence.MongoDb.Configurations; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Genocs.Persistence.MongoDb.Factories; using Genocs.Persistence.MongoDb.Initializers; using Genocs.Persistence.MongoDb.Repositories; -using Genocs.Persistence.MongoDb.Repositories.Clean; -using Genocs.Persistence.MongoDb.Repositories.Mentor; using Genocs.Persistence.MongoDb.Seeders; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -141,19 +140,19 @@ public static IGenocsBuilder AddMongo( /// Adds a MongoDb repository to the DI container. Using Genocs builder support. /// /// The name of the entity. - /// The kind of identifier. + /// The kind of identifier. /// The Genocs builder. /// The collection name where to store data. /// The Genocs builder. - public static IGenocsBuilder AddMongoRepository( - this IGenocsBuilder builder, - string collectionName) - where TEntity : IIdentifiable + public static IGenocsBuilder AddMongoRepository( + this IGenocsBuilder builder, + string collectionName) + where TEntity : IEntity { - builder.Services.AddTransient>(sp => + builder.Services.AddTransient>(sp => { var database = sp.GetRequiredService(); - return new MongoRepository(database, collectionName); + return new MongoDbBaseRepository(database, collectionName); }); return builder; diff --git a/src/Genocs.Persistence.MongoDb/Extensions/ServiceCollectionExtensions.cs b/src/Genocs.Persistence.MongoDb/Extensions/ServiceCollectionExtensions.cs index f3ed6582..ed983fb1 100644 --- a/src/Genocs.Persistence.MongoDb/Extensions/ServiceCollectionExtensions.cs +++ b/src/Genocs.Persistence.MongoDb/Extensions/ServiceCollectionExtensions.cs @@ -14,8 +14,14 @@ public static class ServiceCollectionExtensions internal static void RegisterConventions() { BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128)); - BsonSerializer.RegisterSerializer(typeof(decimal?), - new NullableSerializer(new DecimalSerializer(BsonType.Decimal128))); + + // Move to standard GuidRepresentation + BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.CSharpLegacy)); + + BsonSerializer.RegisterSerializer( + typeof(decimal?), + new NullableSerializer(new DecimalSerializer(BsonType.Decimal128))); + ConventionRegistry.Register("genocs", new ConventionPack { new CamelCaseElementNameConvention(), diff --git a/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj b/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj index 8f2a64d5..7f9f2b16 100644 --- a/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj +++ b/src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj @@ -22,11 +22,11 @@ - + - + diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Clean/IMongoDbEntity.cs b/src/Genocs.Persistence.MongoDb/Repositories/Clean/IMongoDbEntity.cs deleted file mode 100644 index 5520d571..00000000 --- a/src/Genocs.Persistence.MongoDb/Repositories/Clean/IMongoDbEntity.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Genocs.Common.Types; -using MongoDB.Bson; - -namespace Genocs.Persistence.MongoDb.Repositories.Clean; - -/// -/// General purpose Entity used by default in MongoDB. -/// -public interface IMongoDbEntity : IIdentifiable -{ - -} diff --git a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntity.cs b/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntity.cs deleted file mode 100644 index 5a956c2f..00000000 --- a/src/Genocs.Persistence.MongoDb/Repositories/Clean/MongoDbRepositoryBaseOfEntity.cs +++ /dev/null @@ -1,20 +0,0 @@ -using MongoDB.Bson; - -namespace Genocs.Persistence.MongoDb.Repositories.Clean; - -/// -/// Implements base class for IRepository for MongoDB. -/// -/// Type of the Entity for this repository. -public class MongoDbRepositoryBase : MongoDbRepositoryBase - where TEntity : class, IMongoDbEntity -{ - /// - /// The standard constructor. - /// - /// The MongoDB database provider. - public MongoDbRepositoryBase(IMongoDatabaseProvider databaseProvider) - : base(databaseProvider) - { - } -} \ No newline at end of file diff --git a/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbRepository.cs b/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbRepository.cs deleted file mode 100644 index 5cb580d4..00000000 --- a/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Genocs.Common.Types; -using Genocs.Persistence.MongoDb.Repositories.Mentor; -using MongoDB.Bson; - -namespace Genocs.Persistence.MongoDb.Repositories; - -/// -/// The MongoDb repository interface. -/// -/// The type of the entity. -public interface IMongoDbRepository : IMongoRepository - where TEntity : IIdentifiable -{ - -} diff --git a/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbSeeder.cs b/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbSeeder.cs index 7c1b0129..a4988961 100644 --- a/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbSeeder.cs +++ b/src/Genocs.Persistence.MongoDb/Repositories/IMongoDbSeeder.cs @@ -11,6 +11,6 @@ public interface IMongoDbSeeder /// Database Seed. /// /// The database. - /// The async Task + /// The async Task. Task SeedAsync(IMongoDatabase database); } \ No newline at end of file diff --git a/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj b/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj index dc646c6b..0b44127c 100644 --- a/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj +++ b/src/Genocs.Persistence.Redis/Genocs.Persistence.Redis.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj index 85535739..e51e8049 100644 --- a/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj +++ b/src/Genocs.QueryBuilder.UnitTests/Genocs.QueryBuilder.UnitTests.csproj @@ -11,9 +11,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all @@ -31,8 +31,8 @@ - - + + diff --git a/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj b/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj index 0fe03ceb..eda6a48d 100644 --- a/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj +++ b/src/Genocs.Secrets.AzureKeyVault/Genocs.Secrets.AzureKeyVault.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj b/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj index fb6c47d4..61c373ee 100644 --- a/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj +++ b/src/Genocs.Secrets.Vault/Genocs.Secrets.Vault.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Security/Genocs.Security.csproj b/src/Genocs.Security/Genocs.Security.csproj index 7a1bcb23..911dec65 100644 --- a/src/Genocs.Security/Genocs.Security.csproj +++ b/src/Genocs.Security/Genocs.Security.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj b/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj index 8b6bdeb0..c2e209e7 100644 --- a/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj +++ b/src/Genocs.ServiceBusAzure/Genocs.ServiceBusAzure.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj b/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj index 75bdcf5c..850a07f9 100644 --- a/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj +++ b/src/Genocs.Tracing.Jaeger.RabbitMQ/Genocs.Tracing.Jaeger.RabbitMQ.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.Tracing/Extensions.cs b/src/Genocs.Tracing/Extensions.cs index 400e1281..9ff0aef4 100644 --- a/src/Genocs.Tracing/Extensions.cs +++ b/src/Genocs.Tracing/Extensions.cs @@ -64,8 +64,8 @@ public static IGenocsBuilder AddOpenTelemetry(this IGenocsBuilder builder) // No OpenTelemetryTracing in case of missing LoggerSettings if (loggerOptions.Mongo != null && loggerOptions.Mongo.Enabled) { - // you should add MongoDB.Driver.Core.Extensions.OpenTelemetry NuGet package - provider.AddMongoDBInstrumentation(); + // Check for MongoDB config + provider.AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources"); } // Check for Console config diff --git a/src/Genocs.Tracing/Genocs.Tracing.csproj b/src/Genocs.Tracing/Genocs.Tracing.csproj index e953fb3d..5c92a7dd 100644 --- a/src/Genocs.Tracing/Genocs.Tracing.csproj +++ b/src/Genocs.Tracing/Genocs.Tracing.csproj @@ -24,14 +24,13 @@ - - - + + + - diff --git a/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj b/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj index 7aab826a..f43a5c4c 100644 --- a/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj +++ b/src/Genocs.WebApi.CQRS/Genocs.WebApi.CQRS.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj b/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj index 03d8f1cb..e5767a51 100644 --- a/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj +++ b/src/Genocs.WebApi.Security/Genocs.WebApi.Security.csproj @@ -22,7 +22,7 @@ - + @@ -35,6 +35,6 @@ - + diff --git a/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj b/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj index 4a8d9504..c794b33e 100644 --- a/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj +++ b/src/Genocs.WebApi.Swagger/Genocs.WebApi.Swagger.csproj @@ -22,15 +22,15 @@ - + - - - - - + + + + + diff --git a/src/Genocs.WebApi/EndpointsBuilder.cs b/src/Genocs.WebApi/EndpointsBuilder.cs index 12bb2d69..efad9aa9 100644 --- a/src/Genocs.WebApi/EndpointsBuilder.cs +++ b/src/Genocs.WebApi/EndpointsBuilder.cs @@ -17,14 +17,15 @@ public EndpointsBuilder(IEndpointRouteBuilder routeBuilder, WebApiEndpointDefini _definitions = definitions; } - public IEndpointsBuilder Get(string path, - Func? context = null, - Action? endpoint = null, - bool auth = false, - string? roles = null, - params string[] policies) + public IEndpointsBuilder Get( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies) { - var builder = _routeBuilder.MapGet(path, ctx => context.Invoke(ctx)); + var builder = _routeBuilder.MapGet(path, ctx => context?.Invoke(ctx)); endpoint?.Invoke(builder); ApplyAuthRolesAndPolicies(builder, auth, roles, policies); AddEndpointDefinition(HttpMethods.Get, path); @@ -202,8 +203,8 @@ private void AddEndpointDefinition(string method, string path) private void AddEndpointDefinition(string method, string path) => AddEndpointDefinition(method, path, typeof(T), null); - private void AddEndpointDefinition(string method, string path) - => AddEndpointDefinition(method, path, typeof(T), typeof(U)); + private void AddEndpointDefinition(string method, string path) + => AddEndpointDefinition(method, path, typeof(Ta), typeof(Tu)); private void AddEndpointDefinition(string method, string path, Type input, Type? output) { diff --git a/src/Genocs.WebApi/Extensions.cs b/src/Genocs.WebApi/Extensions.cs index ff9a67d5..18e8c96c 100644 --- a/src/Genocs.WebApi/Extensions.cs +++ b/src/Genocs.WebApi/Extensions.cs @@ -27,31 +27,15 @@ namespace Genocs.WebApi; public static class Extensions { - private static readonly byte[] InvalidJsonRequestBytes = Encoding.UTF8.GetBytes("An invalid JSON was sent."); private const string SectionName = "webApi"; private const string RegistryName = "webApi"; private const string EmptyJsonObject = "{}"; private const string LocationHeader = "Location"; + private const string JsonContentType = "application/json"; + private static readonly byte[] InvalidJsonRequestBytes = Encoding.UTF8.GetBytes("An invalid JSON was sent."); private static bool _bindRequestFromRoute; - public static IApplicationBuilder UseEndpoints(this IApplicationBuilder app, Action build, - bool useAuthorization = true, Action middleware = null) - { - var definitions = app.ApplicationServices.GetRequiredService(); - app.UseRouting(); - if (useAuthorization) - { - app.UseAuthorization(); - } - - middleware?.Invoke(app); - - app.UseEndpoints(router => build(new EndpointsBuilder(router, definitions))); - - return app; - } - [Description("By default System JSON serializer is being used. If Newtonsoft JSON serializer is used then it sets Kestrel's and IIS ServerOptions AllowSynchronousIO = true")] public static IGenocsBuilder AddWebApi( this IGenocsBuilder builder, @@ -79,8 +63,6 @@ public static IGenocsBuilder AddWebApi( Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) } }; - jsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); - var factory = new Open.Serialization.Json.System.JsonSerializerFactory(jsonSerializerOptions); jsonSerializer = factory.GetSerializer(); @@ -95,13 +77,15 @@ public static IGenocsBuilder AddWebApi( builder.Services.AddSingleton(jsonSerializer); builder.Services.AddSingleton(); builder.Services.AddSingleton(new WebApiEndpointDefinitions()); + var options = builder.GetOptions(sectionName); builder.Services.AddSingleton(options); + _bindRequestFromRoute = options.BindRequestFromRoute; var mvcCoreBuilder = builder.Services - .AddLogging() - .AddMvcCore(); + .AddLogging() + .AddMvcCore(); mvcCoreBuilder.AddMvcOptions(o => { @@ -142,16 +126,39 @@ public static IGenocsBuilder AddErrorHandler(this IGenocsBuilder builder) return builder; } + public static IApplicationBuilder UseEndpoints( + this IApplicationBuilder app, + Action build, + bool useAuthorization = true, + Action? middleware = null) + { + WebApiEndpointDefinitions definitions = app.ApplicationServices.GetRequiredService(); + + app.UseRouting(); + if (useAuthorization) + { + app.UseAuthorization(); + } + + middleware?.Invoke(app); + + app.UseEndpoints(router => build(new EndpointsBuilder(router, definitions))); + + return app; + } + public static IApplicationBuilder UseErrorHandler(this IApplicationBuilder builder) => builder.UseMiddleware(); - public static IApplicationBuilder UseAllForwardedHeaders(this IApplicationBuilder builder, - bool resetKnownNetworksAndProxies = true) + public static IApplicationBuilder UseAllForwardedHeaders( + this IApplicationBuilder builder, + bool resetKnownNetworksAndProxies = true) { - var forwardingOptions = new ForwardedHeadersOptions + ForwardedHeadersOptions forwardingOptions = new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.All }; + if (resetKnownNetworksAndProxies) { forwardingOptions.KnownNetworks.Clear(); @@ -174,8 +181,7 @@ public static T BindId(this T model, Expression> expression) public static T BindId(this T model, Expression> expression) => model.Bind(expression, Guid.NewGuid().ToString("N")); - private static TModel Bind(this TModel model, Expression> expression, - object value) + private static TModel Bind(this TModel model, Expression> expression, object value) { if (!(expression.Body is MemberExpression memberExpression)) { @@ -189,8 +195,10 @@ private static TModel Bind(this TModel model, Expression x.Name.ToLowerInvariant().StartsWith($"<{propertyName}>")); + .SingleOrDefault(x => x.Name.ToLowerInvariant().StartsWith($"<{propertyName}>")); + if (field is null) { return model; @@ -201,15 +209,16 @@ private static TModel Bind(this TModel model, Expression ReadJsonAsync(this HttpContext httpContext) } } - public static T ReadQuery(this HttpContext context) where T : class + public static T ReadQuery(this HttpContext context) + where T : class { var request = context.Request; - RouteValueDictionary values = null; + RouteValueDictionary? values = null; if (request.HasRouteData()) { values = request.HttpContext.GetRouteData().Values; diff --git a/src/Genocs.WebApi/Formatters/JsonInputFormatter.cs b/src/Genocs.WebApi/Formatters/JsonInputFormatter.cs index 81780df7..e262e90b 100644 --- a/src/Genocs.WebApi/Formatters/JsonInputFormatter.cs +++ b/src/Genocs.WebApi/Formatters/JsonInputFormatter.cs @@ -33,7 +33,7 @@ public async Task ReadAsync(InputFormatterContext context) } var request = context.HttpContext.Request; - var json = string.Empty; + string json = string.Empty; if (request.Body is not null) { using var streamReader = new StreamReader(request.Body); @@ -45,7 +45,7 @@ public async Task ReadAsync(InputFormatterContext context) json = EmptyJson; } - var result = method.Invoke(_serializer, new object[] { json }); + object? result = method.Invoke(_serializer, new object[] { json }); return await InputFormatterResult.SuccessAsync(result); } diff --git a/src/Genocs.WebApi/Genocs.WebApi.csproj b/src/Genocs.WebApi/Genocs.WebApi.csproj index b9773d22..aa0b5a0c 100644 --- a/src/Genocs.WebApi/Genocs.WebApi.csproj +++ b/src/Genocs.WebApi/Genocs.WebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/Genocs.WebApi/IEndpointsBuilder.cs b/src/Genocs.WebApi/IEndpointsBuilder.cs index 89a49f33..ab7e9fda 100644 --- a/src/Genocs.WebApi/IEndpointsBuilder.cs +++ b/src/Genocs.WebApi/IEndpointsBuilder.cs @@ -39,26 +39,46 @@ IEndpointsBuilder Post( string? roles = null, params string[] policies); - IEndpointsBuilder Post(string path, Func? context = null, - Action? endpoint = null, bool auth = false, string? roles = null, - params string[] policies) + IEndpointsBuilder Post( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies) where T : class; - IEndpointsBuilder Put(string path, Func? context = null, - Action? endpoint = null, bool auth = false, string? roles = null, - params string[] policies); + IEndpointsBuilder Put( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies); - IEndpointsBuilder Put(string path, Func? context = null, - Action? endpoint = null, bool auth = false, string? roles = null, - params string[] policies) + IEndpointsBuilder Put( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies) where T : class; - IEndpointsBuilder Delete(string path, Func? context = null, - Action? endpoint = null, bool auth = false, string? roles = null, - params string[] policies); + IEndpointsBuilder Delete( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies); - IEndpointsBuilder Delete(string path, Func? context = null, - Action? endpoint = null, bool auth = false, string? roles = null, - params string[] policies) + IEndpointsBuilder Delete( + string path, + Func? context = null, + Action? endpoint = null, + bool auth = false, + string? roles = null, + params string[] policies) where T : class; } \ No newline at end of file diff --git a/src/Genocs.WebApi/Parsers/JsonParser.cs b/src/Genocs.WebApi/Parsers/JsonParser.cs index 7a2dec07..ae61aff9 100644 --- a/src/Genocs.WebApi/Parsers/JsonParser.cs +++ b/src/Genocs.WebApi/Parsers/JsonParser.cs @@ -3,9 +3,9 @@ namespace Genocs.WebApi.Parsers; -//Credits goes to .NET Foundation Team. -//JSON parser is based on JsonConfigurationFileParser found in Microsoft.Extensions.Configuration.Json library. -//https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs +// Credits goes to .NET Foundation Team. +// JSON parser is based on JsonConfigurationFileParser found in Microsoft.Extensions.Configuration.Json library. +// https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Json/src/JsonConfigurationFileParser.cs public class JsonParser { private readonly Dictionary _data = new(StringComparer.OrdinalIgnoreCase); @@ -24,7 +24,7 @@ public IDictionary Parse(string json) { if (doc.RootElement.ValueKind != JsonValueKind.Object) { - throw new FormatException($"Invalidtop level JSON element: {doc.RootElement.ValueKind}"); + throw new FormatException($"Invalid top level JSON element: {doc.RootElement.ValueKind}"); } VisitElement(doc.RootElement); diff --git a/src/Genocs.WebApi/Requests/IRequestHandler.cs b/src/Genocs.WebApi/Requests/IRequestHandler.cs index 98b70df5..976bdd62 100644 --- a/src/Genocs.WebApi/Requests/IRequestHandler.cs +++ b/src/Genocs.WebApi/Requests/IRequestHandler.cs @@ -1,6 +1,7 @@ namespace Genocs.WebApi.Requests; -public interface IRequestHandler where TRequest : class, IRequest +public interface IRequestHandler + where TRequest : class, IRequest { Task HandleAsync(TRequest request, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/Genocs.WebApi/Requests/RequestDispatcher.cs b/src/Genocs.WebApi/Requests/RequestDispatcher.cs index c6fb597b..5195bfa0 100644 --- a/src/Genocs.WebApi/Requests/RequestDispatcher.cs +++ b/src/Genocs.WebApi/Requests/RequestDispatcher.cs @@ -11,8 +11,8 @@ public RequestDispatcher(IServiceProvider serviceProvider) _serviceProvider = serviceProvider; } - public async Task DispatchAsync(TRequest request, - CancellationToken cancellationToken = default) where TRequest : class, IRequest + public async Task DispatchAsync(TRequest request, CancellationToken cancellationToken = default) + where TRequest : class, IRequest { using var scope = _serviceProvider.CreateScope(); var handler = scope.ServiceProvider.GetRequiredService>(); diff --git a/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj b/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj index fb5c8504..6d8537c6 100644 --- a/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj +++ b/src/apps/api-gateway/Genocs.APIGateway/Genocs.APIGateway.csproj @@ -19,15 +19,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj b/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj index 5b87a02e..9704def8 100644 --- a/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj +++ b/src/apps/identity/Genocs.Identities.Application/Genocs.Identities.Application.csproj @@ -20,16 +20,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/RefreshTokenDocument.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/RefreshTokenDocument.cs index 9b97b073..48820859 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/RefreshTokenDocument.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/RefreshTokenDocument.cs @@ -1,9 +1,9 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; using Genocs.Identities.Application.Domain.Entities; namespace Genocs.Identities.Application.Mongo.Documents; -public class RefreshTokenDocument : IIdentifiable +public class RefreshTokenDocument : IEntity { public Guid Id { get; set; } public Guid UserId { get; set; } diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/UserDocument.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/UserDocument.cs index 8090b063..06ddeb7d 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/UserDocument.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Documents/UserDocument.cs @@ -1,9 +1,10 @@ using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; using Genocs.Identities.Application.Domain.Entities; namespace Genocs.Identities.Application.Mongo.Documents; -public class UserDocument : IIdentifiable +public class UserDocument : IEntity { public Guid Id { get; set; } public string Email { get; set; } diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs index 70ce9a88..97185239 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs @@ -1,5 +1,5 @@ using Genocs.Identities.Application.Mongo.Documents; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using MongoDB.Driver; @@ -11,7 +11,7 @@ public static class Extensions public static IApplicationBuilder UseMongo(this IApplicationBuilder builder) { using var scope = builder.ApplicationServices.CreateScope(); - var users = scope.ServiceProvider.GetService>()?.Collection; + var users = scope.ServiceProvider.GetService>()?.Collection; if (users is null) { diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Queries/Handlers/GetUserHandler.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Queries/Handlers/GetUserHandler.cs index 9dba71ff..ff43d3fb 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Queries/Handlers/GetUserHandler.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Queries/Handlers/GetUserHandler.cs @@ -2,15 +2,15 @@ using Genocs.Identities.Application.DTO; using Genocs.Identities.Application.Mongo.Documents; using Genocs.Identities.Application.Queries; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; namespace Genocs.Identities.Application.Mongo.Queries.Handlers; public class GetUserHandler : IQueryHandler { - private readonly IMongoRepository _userRepository; + private readonly IMongoDbBaseRepository _userRepository; - public GetUserHandler(IMongoRepository userRepository) + public GetUserHandler(IMongoDbBaseRepository userRepository) { _userRepository = userRepository; } diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/RefreshTokenRepository.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/RefreshTokenRepository.cs index 0a4cc536..d449921a 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/RefreshTokenRepository.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/RefreshTokenRepository.cs @@ -1,15 +1,15 @@ using Genocs.Identities.Application.Domain.Entities; using Genocs.Identities.Application.Domain.Repositories; using Genocs.Identities.Application.Mongo.Documents; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; namespace Genocs.Identities.Application.Mongo.Repositories; public class RefreshTokenRepository : IRefreshTokenRepository { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; - public RefreshTokenRepository(IMongoRepository repository) + public RefreshTokenRepository(IMongoDbBaseRepository repository) { _repository = repository; } diff --git a/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/UserRepository.cs b/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/UserRepository.cs index f20e43a6..4228fed7 100644 --- a/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/UserRepository.cs +++ b/src/apps/identity/Genocs.Identities.Application/Mongo/Repositories/UserRepository.cs @@ -1,15 +1,15 @@ using Genocs.Identities.Application.Domain.Entities; using Genocs.Identities.Application.Domain.Repositories; using Genocs.Identities.Application.Mongo.Documents; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; namespace Genocs.Identities.Application.Mongo.Repositories; public class UserRepository : IUserRepository { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; - public UserRepository(IMongoRepository repository) + public UserRepository(IMongoDbBaseRepository repository) { _repository = repository; } diff --git a/src/apps/orders/Genocs.Orders.WebApi/Commands/Handlers/CreateOrderHandler.cs b/src/apps/orders/Genocs.Orders.WebApi/Commands/Handlers/CreateOrderHandler.cs index 80dcac2a..880aa814 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Commands/Handlers/CreateOrderHandler.cs +++ b/src/apps/orders/Genocs.Orders.WebApi/Commands/Handlers/CreateOrderHandler.cs @@ -4,20 +4,20 @@ using Genocs.Orders.WebApi.Domain; using Genocs.Orders.WebApi.Events; using Genocs.Orders.WebApi.Services; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; namespace Genocs.Orders.WebApi.Commands.Handlers; public class CreateOrderHandler : ICommandHandler { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; private readonly IBusPublisher _publisher; private readonly IMessageOutbox _outbox; private readonly IProductServiceClient _productServiceClient; private readonly ILogger _logger; public CreateOrderHandler( - IMongoRepository repository, + IMongoDbBaseRepository repository, IBusPublisher publisher, IMessageOutbox outbox, IProductServiceClient productServiceClient, diff --git a/src/apps/orders/Genocs.Orders.WebApi/Domain/Order.cs b/src/apps/orders/Genocs.Orders.WebApi/Domain/Order.cs index 3a1b1f69..ad0cfb06 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Domain/Order.cs +++ b/src/apps/orders/Genocs.Orders.WebApi/Domain/Order.cs @@ -1,8 +1,8 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; namespace Genocs.Orders.WebApi.Domain; -public class Order : IIdentifiable +public class Order : IEntity { public Guid Id { get; private set; } public Guid CustomerId { get; private set; } diff --git a/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj b/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj index 07777352..7018f219 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj +++ b/src/apps/orders/Genocs.Orders.WebApi/Genocs.Orders.WebApi.csproj @@ -29,22 +29,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs b/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs index f6d07ca8..2efca4c6 100644 --- a/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs +++ b/src/apps/orders/Genocs.Orders.WebApi/Queries/Handlers/GetOrderHandler.cs @@ -1,15 +1,15 @@ using Genocs.Core.CQRS.Queries; using Genocs.Orders.WebApi.Domain; using Genocs.Orders.WebApi.DTO; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; namespace Genocs.Orders.WebApi.Queries.Handlers; public class GetOrderHandler : IQueryHandler { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; - public GetOrderHandler(IMongoRepository repository) + public GetOrderHandler(IMongoDbBaseRepository repository) { _repository = repository; } diff --git a/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs b/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs index 8f5cde26..51ac3aec 100644 --- a/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs +++ b/src/apps/products/Genocs.Products.WebApi/Commands/Handlers/CreateProductHandler.cs @@ -1,7 +1,7 @@ using Genocs.Core.CQRS.Commands; using Genocs.MessageBrokers; using Genocs.MessageBrokers.Outbox; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Genocs.Products.WebApi.Domain; using Genocs.Products.WebApi.Events; @@ -9,13 +9,13 @@ namespace Genocs.Products.WebApi.Commands.Handlers; public class CreateProductHandler : ICommandHandler { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; private readonly IBusPublisher _publisher; private readonly IMessageOutbox _outbox; private readonly ILogger _logger; public CreateProductHandler( - IMongoRepository repository, + IMongoDbBaseRepository repository, IBusPublisher publisher, IMessageOutbox outbox, ILogger logger) diff --git a/src/apps/products/Genocs.Products.WebApi/Domain/Product.cs b/src/apps/products/Genocs.Products.WebApi/Domain/Product.cs index 986e8262..087a076f 100644 --- a/src/apps/products/Genocs.Products.WebApi/Domain/Product.cs +++ b/src/apps/products/Genocs.Products.WebApi/Domain/Product.cs @@ -1,11 +1,11 @@ -using Genocs.Common.Types; +using Genocs.Core.Domain.Entities; namespace Genocs.Products.WebApi.Domain; /// /// The product definition. /// -public class Product : IIdentifiable +public class Product : IEntity { public Guid Id { get; private set; } public string SKU { get; private set; } diff --git a/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj b/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj index 851694b3..499fbed1 100644 --- a/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj +++ b/src/apps/products/Genocs.Products.WebApi/Genocs.Products.WebApi.csproj @@ -30,22 +30,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/GetProductHandler.cs b/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/GetProductHandler.cs index 2becb5d1..2fae624e 100644 --- a/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/GetProductHandler.cs +++ b/src/apps/products/Genocs.Products.WebApi/Queries/Handlers/GetProductHandler.cs @@ -1,14 +1,14 @@ using Genocs.Core.CQRS.Queries; -using Genocs.Persistence.MongoDb.Repositories.Mentor; +using Genocs.Persistence.MongoDb.Domain.Repositories; using Genocs.Products.WebApi.DTO; namespace Genocs.Products.WebApi.Queries.Handlers; public class GetProductHandler : IQueryHandler { - private readonly IMongoRepository _repository; + private readonly IMongoDbBaseRepository _repository; - public GetProductHandler(IMongoRepository repository) + public GetProductHandler(IMongoDbBaseRepository repository) { _repository = repository; } diff --git a/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj b/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj index 1b17a16c..6409fb9b 100644 --- a/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj +++ b/src/apps/signalr/Genocs.SignalR.WebApi/Genocs.SignalR.WebApi.csproj @@ -31,23 +31,23 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +