-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
15 changes: 10 additions & 5 deletions
15
src/Orion.Application.Core/Commands/UserCreate/UserCreateRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
using MediatR; | ||
using Orion.Application.Core.Notifications.UserCreated; | ||
using Orion.Domain.Core.Services.Interfaces; | ||
|
||
namespace Orion.Application.Core.Commands.UserCreate; | ||
|
||
public class UserCreateRequestHandler : IRequestHandler<UserCreateRequest, UserCreateResponse> | ||
{ | ||
private readonly IUserService _userService; | ||
|
||
public UserCreateRequestHandler(IUserService userService) | ||
private readonly IMediator _mediator; | ||
|
||
public UserCreateRequestHandler(IUserService userService, IMediator mediator) | ||
{ | ||
_userService = userService; | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<UserCreateResponse> Handle(UserCreateRequest request, CancellationToken cancellationToken) | ||
{ | ||
var customerCreated = await _userService.AddAsync(request); | ||
var userCreated = await _userService.AddAsync(request); | ||
|
||
await _mediator.Publish(new UserCreatedNotification(userCreated), cancellationToken); | ||
|
||
return (UserCreateResponse)customerCreated; | ||
return (UserCreateResponse)userCreated; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Orion.Application.Core/Notifications/UserCreated/UserCreatedNotification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using MediatR; | ||
using Orion.Domain.Core.Entities; | ||
|
||
namespace Orion.Application.Core.Notifications.UserCreated | ||
{ | ||
public class UserCreatedNotification : INotification | ||
{ | ||
public UserCreatedNotification(User user) | ||
{ | ||
Entity = user; | ||
} | ||
|
||
public User Entity { get; set; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Orion.Application.Core/Notifications/UserCreated/UserCreatedNotificationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using Newtonsoft.Json; | ||
|
||
namespace Orion.Application.Core.Notifications.UserCreated | ||
{ | ||
public class UserCreatedNotificationHandler : INotificationHandler<UserCreatedNotification> | ||
{ | ||
private readonly ILogger<UserCreatedNotificationHandler> _logger; | ||
|
||
public UserCreatedNotificationHandler(ILogger<UserCreatedNotificationHandler> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("A notification {notificationType} has been received. Notification details: {notification}", | ||
nameof(UserCreatedNotification), | ||
JsonConvert.SerializeObject(notification, Formatting.Indented)); | ||
|
||
await Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters