Skip to content

Commit

Permalink
Many features. (#58)
Browse files Browse the repository at this point in the history
* Upgraded NuGet packages.

* Removed EventDb.

* Clean domain events and use the new Raise methods.
  • Loading branch information
Utar94 authored Mar 26, 2024
1 parent cfb6ae1 commit c7e20a7
Show file tree
Hide file tree
Showing 53 changed files with 97 additions and 246 deletions.
2 changes: 1 addition & 1 deletion src/Logitar.Identity.Demo/Logitar.Identity.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
15 changes: 8 additions & 7 deletions src/Logitar.Identity.Domain/ApiKeys/ApiKeyAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public ApiKeyAggregate(AggregateId id) : base(id)
public ApiKeyAggregate(DisplayNameUnit displayName, Password secret, TenantId? tenantId = null, ActorId actorId = default, ApiKeyId? id = null)
: base((id ?? ApiKeyId.NewId()).AggregateId)
{
Raise(new ApiKeyCreatedEvent(actorId, displayName, secret, tenantId));
Raise(new ApiKeyCreatedEvent(displayName, secret, tenantId), actorId);
}
/// <summary>
/// Applies the specified event.
Expand Down Expand Up @@ -135,7 +135,7 @@ public void AddRole(RoleAggregate role, ActorId actorId = default)

if (!HasRole(role))
{
Raise(new ApiKeyRoleAddedEvent(actorId, role.Id));
Raise(new ApiKeyRoleAddedEvent(role.Id), actorId);
}
}
/// <summary>
Expand Down Expand Up @@ -166,7 +166,7 @@ public void Authenticate(string secret, ActorId? actorId = null)
}

actorId ??= new(Id.Value);
Raise(new ApiKeyAuthenticatedEvent(actorId.Value));
Raise(new ApiKeyAuthenticatedEvent(), actorId.Value);
}
/// <summary>
/// Applies the specified event.
Expand All @@ -185,7 +185,7 @@ public void Delete(ActorId actorId = default)
{
if (!IsDeleted)
{
Raise(new ApiKeyDeletedEvent(actorId));
Raise(new ApiKeyDeletedEvent(), actorId);
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public void RemoveRole(RoleAggregate role, ActorId actorId = default)
{
if (HasRole(role))
{
Raise(new ApiKeyRoleRemovedEvent(actorId, role.Id));
Raise(new ApiKeyRoleRemovedEvent(role.Id), actorId);
}
}
/// <summary>
Expand Down Expand Up @@ -282,8 +282,7 @@ public void Update(ActorId actorId = default)
{
if (_updatedEvent.HasChanges)
{
_updatedEvent.ActorId = actorId;
Raise(_updatedEvent);
Raise(_updatedEvent, actorId, DateTime.Now);
_updatedEvent = new();
}
}
Expand Down Expand Up @@ -325,3 +324,5 @@ protected virtual void Apply(ApiKeyUpdatedEvent @event)
/// <returns>The string representation.</returns>
public override string ToString() => $"{DisplayName.Value} | {base.ToString()}";
}

// Added: Aggregate Raise methods.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@ namespace Logitar.Identity.Domain.ApiKeys.Events;
/// <summary>
/// The event raised when an API key is authenticated.
/// </summary>
public record ApiKeyAuthenticatedEvent : DomainEvent, INotification
{
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyAuthenticatedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public ApiKeyAuthenticatedEvent(ActorId actorId)
{
ActorId = actorId;
}
}
public record ApiKeyAuthenticatedEvent : DomainEvent, INotification;
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public record ApiKeyCreatedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyCreatedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="displayName">The display name of the API key.</param>
/// <param name="secret">The secret of the API key.</param>
/// <param name="tenantId">The tenant identifier of the API key.</param>
public ApiKeyCreatedEvent(ActorId actorId, DisplayNameUnit displayName, Password secret, TenantId? tenantId)
public ApiKeyCreatedEvent(DisplayNameUnit displayName, Password secret, TenantId? tenantId)
{
ActorId = actorId;
DisplayName = displayName;
Secret = secret;
TenantId = tenantId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public record ApiKeyDeletedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyDeletedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public ApiKeyDeletedEvent(ActorId actorId)
public ApiKeyDeletedEvent()
{
ActorId = actorId;
IsDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public record ApiKeyRoleAddedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyRoleAddedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="roleId">The role identifier.</param>
public ApiKeyRoleAddedEvent(ActorId actorId, RoleId roleId)
public ApiKeyRoleAddedEvent(RoleId roleId)
{
ActorId = actorId;
RoleId = roleId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public record ApiKeyRoleRemovedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="ApiKeyRoleRemovedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="roleId">The role identifier.</param>
public ApiKeyRoleRemovedEvent(ActorId actorId, RoleId roleId)
public ApiKeyRoleRemovedEvent(RoleId roleId)
{
ActorId = actorId;
RoleId = roleId;
}
}
8 changes: 4 additions & 4 deletions src/Logitar.Identity.Domain/Logitar.Identity.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.31" />
<PackageReference Include="Logitar.EventSourcing" Version="5.0.1" />
<PackageReference Include="libphonenumber-csharp" Version="8.13.33" />
<PackageReference Include="Logitar.EventSourcing" Version="5.1.0" />
<PackageReference Include="Logitar.Security" Version="6.1.1" />
<PackageReference Include="MediatR.Contracts" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="7.4.1" />
<PackageReference Include="NodaTime" Version="3.1.11" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public record OneTimePasswordCreatedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="OneTimePasswordCreatedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="expiresOn">The expiration date and time of the One-Time Password (OTP).</param>
/// <param name="maximumAttempts">The maximum number of attempts of the One-Time Password (OTP).</param>
/// <param name="password">The encoded value of the One-Time Password (OTP).</param>
/// <param name="tenantId">The tenant identifier of the One-Time Password (OTP).</param>
public OneTimePasswordCreatedEvent(ActorId actorId, DateTime? expiresOn, int? maximumAttempts, Password password, TenantId? tenantId)
public OneTimePasswordCreatedEvent(DateTime? expiresOn, int? maximumAttempts, Password password, TenantId? tenantId)
{
ActorId = actorId;
ExpiresOn = expiresOn;
MaximumAttempts = maximumAttempts;
Password = password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public record OneTimePasswordDeletedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="OneTimePasswordDeletedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public OneTimePasswordDeletedEvent(ActorId actorId)
public OneTimePasswordDeletedEvent()
{
ActorId = actorId;
IsDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@ namespace Logitar.Identity.Domain.Passwords.Events;
/// <summary>
/// The event raised when a One-Time Password (OTP) validation failed.
/// </summary>
public record OneTimePasswordValidationFailedEvent : DomainEvent, INotification
{
/// <summary>
/// Initializes a new instance of the <see cref="OneTimePasswordValidationFailedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public OneTimePasswordValidationFailedEvent(ActorId actorId)
{
ActorId = actorId;
}
}
public record OneTimePasswordValidationFailedEvent : DomainEvent, INotification;
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@ namespace Logitar.Identity.Domain.Passwords.Events;
/// <summary>
/// The event raised when a One-Time Password (OTP) is successfully validated.
/// </summary>
public record OneTimePasswordValidationSucceededEvent : DomainEvent, INotification
{
/// <summary>
/// Initializes a new instance of the <see cref="OneTimePasswordValidationSucceededEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public OneTimePasswordValidationSucceededEvent(ActorId actorId)
{
ActorId = actorId;
}
}
public record OneTimePasswordValidationSucceededEvent : DomainEvent, INotification;
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public OneTimePasswordAggregate(Password password, TenantId? tenantId = null, Da
new MaximumAttemptsValidator().ValidateAndThrow(maximumAttempts.Value);
}

Raise(new OneTimePasswordCreatedEvent(actorId, expiresOn, maximumAttempts, password, tenantId));
Raise(new OneTimePasswordCreatedEvent(expiresOn, maximumAttempts, password, tenantId), actorId);
}
/// <summary>
/// Applies the specified event.
Expand All @@ -104,7 +104,7 @@ public void Delete(ActorId actorId = default)
{
if (!IsDeleted)
{
Raise(new OneTimePasswordDeletedEvent(actorId));
Raise(new OneTimePasswordDeletedEvent(), actorId);
}
}

Expand Down Expand Up @@ -157,8 +157,7 @@ public void Update(ActorId actorId = default)
{
if (_updatedEvent.HasChanges)
{
_updatedEvent.ActorId = actorId;
Raise(_updatedEvent);
Raise(_updatedEvent, actorId, DateTime.Now);
_updatedEvent = new();
}
}
Expand Down Expand Up @@ -206,11 +205,11 @@ public void Validate(string password, ActorId actorId = default)
}
else if (_password == null || !_password.IsMatch(password))
{
Raise(new OneTimePasswordValidationFailedEvent(actorId));
Raise(new OneTimePasswordValidationFailedEvent(), actorId);
throw new IncorrectOneTimePasswordPasswordException(this, password);
}

Raise(new OneTimePasswordValidationSucceededEvent(actorId));
Raise(new OneTimePasswordValidationSucceededEvent(), actorId);
}
/// <summary>
/// Applies the specified event.
Expand Down
4 changes: 1 addition & 3 deletions src/Logitar.Identity.Domain/Roles/Events/RoleCreatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public record RoleCreatedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="RoleCreatedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="tenantId">The tenant identifier of the role.</param>
/// <param name="uniqueName">The unique name of the role.</param>
public RoleCreatedEvent(ActorId actorId, TenantId? tenantId, UniqueNameUnit uniqueName)
public RoleCreatedEvent(TenantId? tenantId, UniqueNameUnit uniqueName)
{
ActorId = actorId;
TenantId = tenantId;
UniqueName = uniqueName;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Logitar.Identity.Domain/Roles/Events/RoleDeletedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public record RoleDeletedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="RoleDeletedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public RoleDeletedEvent(ActorId actorId)
public RoleDeletedEvent()
{
ActorId = actorId;
IsDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public record RoleUniqueNameChangedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="RoleUniqueNameChangedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="uniqueName">The unique name of the role.</param>
public RoleUniqueNameChangedEvent(ActorId actorId, UniqueNameUnit uniqueName)
public RoleUniqueNameChangedEvent(UniqueNameUnit uniqueName)
{
ActorId = actorId;
UniqueName = uniqueName;
}
}
9 changes: 4 additions & 5 deletions src/Logitar.Identity.Domain/Roles/RoleAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public RoleAggregate(AggregateId id) : base(id)
public RoleAggregate(UniqueNameUnit uniqueName, TenantId? tenantId = null, ActorId actorId = default, RoleId? id = null)
: base((id ?? RoleId.NewId()).AggregateId)
{
Raise(new RoleCreatedEvent(actorId, tenantId, uniqueName));
Raise(new RoleCreatedEvent(tenantId, uniqueName), actorId);
}
/// <summary>
/// Applies the specified event.
Expand All @@ -114,7 +114,7 @@ public void Delete(ActorId actorId = default)
{
if (!IsDeleted)
{
Raise(new RoleDeletedEvent(actorId));
Raise(new RoleDeletedEvent(), actorId);
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ public void SetUniqueName(UniqueNameUnit uniqueName, ActorId actorId = default)
{
if (uniqueName != _uniqueName)
{
Raise(new RoleUniqueNameChangedEvent(actorId, uniqueName));
Raise(new RoleUniqueNameChangedEvent(uniqueName), actorId);
}
}
/// <summary>
Expand All @@ -181,8 +181,7 @@ public void Update(ActorId actorId = default)
{
if (_updatedEvent.HasChanges)
{
_updatedEvent.ActorId = actorId;
Raise(_updatedEvent);
Raise(_updatedEvent, actorId, DateTime.Now);
_updatedEvent = new();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public record SessionCreatedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="SessionCreatedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="secret">The secret of the session.</param>
/// <param name="userId">The identifier of the user owning the session.</param>
public SessionCreatedEvent(ActorId actorId, Password? secret, UserId userId)
public SessionCreatedEvent(Password? secret, UserId userId)
{
ActorId = actorId;
Secret = secret;
UserId = userId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public record SessionDeletedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="SessionDeletedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public SessionDeletedEvent(ActorId actorId)
public SessionDeletedEvent()
{
ActorId = actorId;
IsDeleted = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ public record SessionRenewedEvent : DomainEvent, INotification
/// <summary>
/// Initializes a new instance of the <see cref="SessionRenewedEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
/// <param name="secret">The new secret of the session.</param>
public SessionRenewedEvent(ActorId actorId, Password secret)
public SessionRenewedEvent(Password secret)
{
ActorId = actorId;
Secret = secret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,4 @@ namespace Logitar.Identity.Domain.Sessions.Events;
/// <summary>
/// The event raised when an active session is signed-out.
/// </summary>
public record SessionSignedOutEvent : DomainEvent, INotification
{
/// <summary>
/// Initializes a new instance of the <see cref="SessionSignedOutEvent"/> class.
/// </summary>
/// <param name="actorId">The actor identifier.</param>
public SessionSignedOutEvent(ActorId actorId)
{
ActorId = actorId;
}
}
public record SessionSignedOutEvent : DomainEvent, INotification;
Loading

0 comments on commit c7e20a7

Please sign in to comment.