Skip to content

Commit 712a4ea

Browse files
committed
Update Genocs library for .NET 9.0 compatibility
- Added new package release notes directing users to the change log on GitHub. - Changed `IDatabaseInitializer` from `internal` to `public`. - Updated `AggregateRoot` and `Entity` classes to use `DefaultIdType` and modified `DomainEvents` to use lists. - Expanded `IRepository` interface with generic versions and introduced read/write repository interfaces. - Modified `TableMappingAttribute` to include a constructor for the `Name` property. - Refactored `GenocsException` for concise syntax. - Enhanced `ConnectionStringSecurer` and `ConnectionStringValidator` with new logic for database providers. - Introduced `ApplicationDbContext`, `ApplicationDbInitializer`, and `ApplicationDbSeeder` for database management. - Implemented `DatabaseInitializer` for application-specific data initialization. - Created `ApplicationDbRepository` for Ardalis Specification querying. - Updated project references to version 7.2.4 for consistency. - Refactored `Startup` class for better organization of service registrations. - Added `GetAuditLogsRequestHandler` for handling audit log requests with MediatR. - Introduced `IUnitOfWork` interface for saving changes to the database.
1 parent aeea6c2 commit 712a4ea

File tree

54 files changed

+523
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+523
-200
lines changed

src/Genocs.Auth/Genocs.Auth.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
<Authors>Nocco Giovanni Emanuele</Authors>
1313
<PackageTags>authentication jwt genocs microservice microservices solid solid-principles</PackageTags>
1414
<PackageReadmeFile>README_NUGET.md</PackageReadmeFile>
15-
<PackageReleaseNotes>Upgraded to NET9.0</PackageReleaseNotes>
1615
<EnableNETAnalyzers>True</EnableNETAnalyzers>
1716
<AnalysisLevel>latest</AnalysisLevel>
17+
<PackageReleaseNotes>
18+
The change log and breaking changes are listed here.
19+
https://github.com/Genocs/genocs-library/releases
20+
</PackageReleaseNotes>
1821
</PropertyGroup>
1922

2023
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
2124
<ProjectReference Include="..\Genocs.Security\Genocs.Security.csproj" />
2225
</ItemGroup>
2326

2427
<ItemGroup Condition="'$(Configuration)' != 'Debug'">
25-
<PackageReference Include="Genocs.Security" Version="7.2.3" />
28+
<PackageReference Include="Genocs.Security" Version="7.2.4" />
2629
</ItemGroup>
2730

2831
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">

src/Genocs.Common/Persistence/Initialization/IDatabaseInitializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Genocs.Common.Persistence.Initialization;
44

5-
internal interface IDatabaseInitializer
5+
public interface IDatabaseInitializer
66
{
77
Task InitializeDatabasesAsync(CancellationToken cancellationToken);
88

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
// using System.Collections.Generic;
2-
// using System.Collections.ObjectModel;
3-
// using System.ComponentModel.DataAnnotations.Schema;
4-
// using Genocs.Events.Bus;
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
using Genocs.Core.CQRS.Events;
53

64
namespace Genocs.Core.Domain.Entities;
75

8-
public class AggregateRoot : AggregateRoot<Guid>, IAggregateRoot
9-
{
10-
11-
}
6+
public class AggregateRoot : AggregateRoot<DefaultIdType>, IAggregateRoot;
127

138
public class AggregateRoot<TPrimaryKey>
149
: Entity<TPrimaryKey>, IAggregateRoot<TPrimaryKey>
1510
{
16-
/*
1711
[NotMapped]
18-
public virtual ICollection<IEventData> DomainEvents { get; }
12+
public virtual List<IEvent>? DomainEvents { get; }
1913

2014
public AggregateRoot()
2115
{
22-
DomainEvents = new Collection<IEventData>();
16+
DomainEvents = [];
2317
}
24-
*/
2518
}

src/Genocs.Core/Domain/Entities/Auditing/IAudited.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Genocs.Core.Domain.Entities.Auditing;
66
/// </summary>
77
public interface IAudited : ICreationAudited, IModificationAudited;
88

9-
109
/// <summary>
1110
/// Adds navigation properties to <see cref="IAudited"/> interface for user.
1211
/// </summary>

src/Genocs.Core/Domain/Entities/Entity.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
using System.ComponentModel.DataAnnotations.Schema;
2-
using System.Reflection;
1+
using System.Reflection;
32

43
namespace Genocs.Core.Domain.Entities;
54

65
/// <summary>
7-
/// A shortcut of <see cref="Entity{TPrimaryKey}"/> for most used primary key type (<see cref="Guid"/>).
6+
/// A shortcut of <see cref="Entity{TPrimaryKey}"/> for most used primary key type (<see cref="DefaultIdType"/>).
87
/// </summary>
98
[Serializable]
10-
public abstract class Entity : Entity<Guid>
11-
{
12-
13-
}
9+
public abstract class Entity : Entity<DefaultIdType>;
1410

1511
/// <summary>
1612
/// Basic implementation of IEntity interface.
@@ -25,10 +21,6 @@ public abstract class Entity<TPrimaryKey> : IEntity<TPrimaryKey>
2521
/// </summary>
2622
public virtual TPrimaryKey Id { get; set; } = default!;
2723

28-
29-
[NotMapped]
30-
public List<DomainEvent> DomainEvents { get; } = new();
31-
3224
/// <summary>
3325
/// Checks if this entity is transient (it has not an Id).
3426
/// </summary>
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1-
// using System.Collections.Generic;
2-
// using Genocs.Events.Bus;
1+
using Genocs.Core.CQRS.Events;
32

43
namespace Genocs.Core.Domain.Entities;
54

65
/// <summary>
76
/// Apply this marker interface only to aggregate root entities
87
/// Repositories will only work with aggregate roots, not their children.
98
/// </summary>
10-
public interface IAggregateRoot : IEntity
11-
{
9+
public interface IAggregateRoot : IEntity;
1210

13-
}
11+
public interface IAggregateRoot<TKey> : IEntity<TKey>, IAggregateRoot, IGeneratesDomainEvents;
1412

15-
public interface IAggregateRoot<TKey> : IEntity<TKey>, IAggregateRoot/*, IGeneratesDomainEvents */
16-
{
17-
18-
}
19-
20-
/*
13+
/// <summary>
14+
/// This interface is used to identify a domain event source.
15+
/// </summary>
2116
public interface IGeneratesDomainEvents
2217
{
23-
ICollection<IEventData> DomainEvents { get; }
18+
List<IEvent>? DomainEvents { get; }
2419
}
25-
26-
*/

src/Genocs.Core/Domain/Entities/IEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public interface IEntity
99
/// <summary>
1010
/// Checks if this entity is transient (not persisted to database) />).
1111
/// </summary>
12-
/// <returns>True, if this entity is transient, otherwise false.</returns>
12+
/// <returns>True, if this entity is transient, otherwise False.</returns>
1313
bool IsTransient();
1414
}

src/Genocs.Core/Domain/Entities/IEntityOfTPrimaryKey.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ namespace Genocs.Core.Domain.Entities;
66
/// Defines interface for base entity type. All the domain object must implement this interface.
77
/// </summary>
88
/// <typeparam name="TKey">Type of the primary key of the entity.</typeparam>
9-
public interface IEntity<TKey> : IEntity, IIdentifiable<TKey>
10-
{
11-
}
9+
public interface IEntity<TKey> : IEntity, IIdentifiable<TKey>;

src/Genocs.Core/Domain/Repositories/AutoRepositoryTypesAttribute.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@ namespace Genocs.Core.Domain.Repositories;
55
/// This can be used for DbContext types.
66
/// </summary>
77
[AttributeUsage(AttributeTargets.Class)]
8-
public class AutoRepositoryTypesAttribute : Attribute
8+
public class AutoRepositoryTypesAttribute(
9+
Type repositoryInterface,
10+
Type repositoryInterfaceWithPrimaryKey,
11+
Type repositoryImplementation,
12+
Type repositoryImplementationWithPrimaryKey) : Attribute
913
{
10-
public Type RepositoryInterface { get; }
14+
public Type RepositoryInterface { get; } = repositoryInterface;
1115

12-
public Type RepositoryInterfaceWithPrimaryKey { get; }
16+
public Type RepositoryInterfaceWithPrimaryKey { get; } = repositoryInterfaceWithPrimaryKey;
1317

14-
public Type RepositoryImplementation { get; }
18+
public Type RepositoryImplementation { get; } = repositoryImplementation;
1519

16-
public Type RepositoryImplementationWithPrimaryKey { get; }
20+
public Type RepositoryImplementationWithPrimaryKey { get; } = repositoryImplementationWithPrimaryKey;
1721

1822
public bool WithDefaultRepositoryInterfaces { get; set; }
19-
20-
public AutoRepositoryTypesAttribute(
21-
Type repositoryInterface,
22-
Type repositoryInterfaceWithPrimaryKey,
23-
Type repositoryImplementation,
24-
Type repositoryImplementationWithPrimaryKey)
25-
{
26-
RepositoryInterface = repositoryInterface;
27-
RepositoryInterfaceWithPrimaryKey = repositoryInterfaceWithPrimaryKey;
28-
RepositoryImplementation = repositoryImplementation;
29-
RepositoryImplementationWithPrimaryKey = repositoryImplementationWithPrimaryKey;
30-
}
3123
}

src/Genocs.Core/Domain/Repositories/IRepository.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,30 @@ namespace Genocs.Core.Domain.Repositories;
77
/// Implement generic version instead of this one.
88
/// </summary>
99
public interface IRepository<TEntity, in TKey>
10-
where TEntity : IEntity<TKey>
11-
{
10+
where TEntity : IEntity<TKey>;
1211

13-
}
12+
13+
14+
// The Repository for the Application Db
15+
// I(Read)RepositoryBase<T> is from Ardalis.Specification
16+
17+
/// <summary>
18+
/// The regular read/write repository for an aggregate root.
19+
/// </summary>
20+
public interface IRepository<T> : Ardalis.Specification.IRepositoryBase<T>
21+
where T : class, IAggregateRoot;
22+
23+
/// <summary>
24+
/// The read-only repository for an aggregate root.
25+
/// </summary>
26+
public interface IReadRepository<T> : Ardalis.Specification.IReadRepositoryBase<T>
27+
where T : class, IAggregateRoot;
28+
29+
/// <summary>
30+
/// A special (read/write) repository for an aggregate root,
31+
/// that also adds EntityCreated, EntityUpdated or EntityDeleted
32+
/// events to the DomainEvents of the entities before adding,
33+
/// updating or deleting them.
34+
/// </summary>
35+
public interface IRepositoryWithEvents<T> : Ardalis.Specification.IRepositoryBase<T>
36+
where T : class, IAggregateRoot;

0 commit comments

Comments
 (0)