-
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.
Merge pull request #28 from lrodolfol/refactor/users
Refactor/users
- Loading branch information
Showing
43 changed files
with
254 additions
and
96 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
Registration/src/Domain/Registration.DomainBase/Aggregate/Email.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 System.Text.RegularExpressions; | ||
|
||
namespace Registration.DomainBase.Aggregate; | ||
public class Email | ||
{ | ||
public string Address { get; set; } = null!; | ||
|
||
public Email(string? address) | ||
{ | ||
if(address is not null) | ||
Address = address; | ||
} | ||
|
||
public void Validate() => Regex.IsMatch(Address, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); | ||
} |
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
18 changes: 18 additions & 0 deletions
18
Registration/src/Domain/Registration.DomainCore/EnvironmentConfiguration.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,18 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Registration.DomainCore; | ||
public static class EnvironmentConfiguration | ||
{ | ||
public static readonly IConfigurationRoot ConfigurationRoot = DefineConfiguration(); | ||
|
||
private static IConfigurationRoot DefineConfiguration() | ||
{ | ||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? | ||
Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Dev"; | ||
|
||
if (environment is null) | ||
return new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build(); | ||
|
||
return new ConfigurationBuilder().AddJsonFile($"appsettings.{environment}.json", false, true).Build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Registration/src/Domain/Registration.DomainCore/Events/DomainBaseEvents.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,9 @@ | ||
public abstract class DomainBaseEvents | ||
{ | ||
public DateTime OcurredOn { get; set; } | ||
|
||
public DomainBaseEvents() | ||
{ | ||
OcurredOn = DateTime.UtcNow; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Registration/src/Domain/Registration.DomainCore/Events/UserCreatedEvent.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,12 @@ | ||
namespace Registration.DomainCore.Events; | ||
public class UserCreatedEvent : DomainBaseEvents | ||
{ | ||
public int Id { get; set; } | ||
public string EmailAddress { get; set; } = null!; | ||
|
||
public UserCreatedEvent(int id, string emailAddress) : base() | ||
{ | ||
Id = id; | ||
EmailAddress = emailAddress; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...tration/src/Infrastructure/Registration.Infrastructure/Config/EnvironmentConfiguration.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,18 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Registration.Infrastructure.Config; | ||
public static class EnvironmentConfiguration | ||
{ | ||
public static readonly IConfigurationRoot ConfigurationRoot = DefineConfiguration(); | ||
|
||
private static IConfigurationRoot DefineConfiguration() | ||
{ | ||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? | ||
Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Dev"; | ||
|
||
if(environment is null) | ||
return new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build(); | ||
|
||
return new ConfigurationBuilder().AddJsonFile($"{environment}.json", false, true).Build(); | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
Registration/src/Infrastructure/Registration.Infrastructure/IOC/LoadContainersDI.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
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
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
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
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
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
51 changes: 51 additions & 0 deletions
51
Registration/src/Service/MessageBroker/Messages/NewUserCreated.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,51 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Registration.DomainCore.Events; | ||
using System.Text.Json; | ||
using System.Text; | ||
|
||
namespace MessageBroker.Messages; | ||
public class NewUserCreated : BaseMessageBrokerClient | ||
{ | ||
private readonly UserCreatedEvent _userCreated; | ||
|
||
public NewUserCreated(IConfiguration configuration, UserCreatedEvent userCreated) : base(configuration) | ||
{ | ||
_userCreated = userCreated; | ||
LoadConfig(); | ||
} | ||
|
||
public void PreparePublish() | ||
{ | ||
IMessageBrokerClient rabbitClient = new RabbitMqClient<NewUserCreated>(this); | ||
|
||
rabbitClient.Publish(); | ||
} | ||
|
||
protected override byte[] BuildMessage() | ||
{ | ||
var objBody = new | ||
{ | ||
_userCreated.Id, | ||
_userCreated.EmailAddress, | ||
_userCreated.OcurredOn | ||
}; | ||
|
||
var serialize = JsonSerializer.Serialize(objBody); | ||
var body = Encoding.UTF8.GetBytes(serialize); | ||
|
||
return body; | ||
} | ||
protected override void LoadConfig() | ||
{ | ||
Host = _configuration["MessageBroker:Host"]!; | ||
VirtualHost = _configuration["MessageBroker:VirtualHost"]!; | ||
Port = _configuration["MessageBroker:Port"]!; | ||
UserName = _configuration["MessageBroker:UserName"]!; | ||
Password = _configuration["MessageBroker:Password"]!; | ||
Exchange = _configuration["MessageBroker:UserCreated:Exchange"]!; | ||
RoutingKey = _configuration["MessageBroker:UserCreated:RoutingKey"]!; | ||
Queue = _configuration["MessageBroker:UserCreated:Queue"]!; | ||
|
||
BodyMessage = BuildMessage(); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.