Skip to content

Commit

Permalink
fix acrh inversion of control
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsantana committed Apr 7, 2021
1 parent 627b2a9 commit 0bcab17
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Threading;
using System.Threading.Tasks;
using NetSampleArch.Adapters.Kafka.Handlers.Interfaces;
using NetSampleArch.Infra.CrossCutting.Bus.Interfaces.Handlers;
using NetSampleArch.Infra.CrossCutting.Configuration;
using NetSampleArch.Infra.CrossCutting.Messages.Internal.Events.PersonWasRegistered.Interfaces;
Expand All @@ -12,19 +11,16 @@ public class PersonWasRegisteredHandler
: BaseKafkaHandler<IPersonWasRegisteredEvent>, IEventHandler<IPersonWasRegisteredEvent>
{
public PersonWasRegisteredHandler(ILogger logger, Configuration config)
: base(logger, config)
{

}
: base(logger, config) { }

public async override Task Handle(IPersonWasRegisteredEvent notification, CancellationToken cancellationToken)
{
await KafkaPublisher.SendEventAsync(
topicName: "",
key: "",
@event: null,
cancellationToken
).ConfigureAwait(false);
// await KafkaPublisher.SendEventAsync(
// topicName: "",
// key: "",
// @event: null,
// cancellationToken
// ).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NetSampleArch.Adapters.Kafka.IoC;
using NetSampleArch.Adapters.SQLServer.IoC;
using NetSampleArch.Adapters.SQLServer.Repositories;
using NetSampleArch.Adapters.SQLServer.Repositories.Interfaces;
using NetSampleArch.Adapters.SQLServer.UnitOfWork.Interfaces;
using NetSampleArch.Application.IoC;
using NetSampleArch.Infra.CrossCutting.Bus.Handlers.Events.DomainNotifications.Interfaces;
using NetSampleArch.Infra.CrossCutting.UnitOfWork;

Expand All @@ -26,20 +28,20 @@ public static void Inject(this IServiceCollection services, IConfiguration confi

private static void ConfigureCommomLayer(IServiceCollection services, IConfiguration configuration)
{
//CommomBootstrapper.ConfigureCrossCuttingLayer(services, configuration);
CommonInjectionManager.Inject(services, configuration);
//CrossCutting.Messages.External.V1.IoC.CrossCuttingExternalMessagesBootstrapper.ConfigureCrossCuttingExternalMessages(services);
}

private static void ConfigureApplicationCoreLayer(IServiceCollection services)
{
//ApplicationBootstrapper.ConfigureApplicationLayer(services);
ApplicationInjectionManager.Inject(services);
//DomainBootstrapper.ConfigureDomainLayer(services);
}

private static void ConfigureAdaptersLayer(IServiceCollection services, IConfiguration config)
{
AdapterSqlServerInjectionManager.Inject(services);
AdapterKafkaBootstrapper.ConfigureAdapterKafkaLayer(services);
AdapterKafkaInjectionManager.Inject(services);

services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetService<ISqlServerUnitOfWork>());
services.AddScoped<IPersonSqlServerRepository, PersonSqlServerRepository>();
Expand All @@ -51,9 +53,9 @@ private static void ConfigureMessageHandlerLayer(IServiceCollection services, IC
// Commom
typeof(IDomainNotificationEventHandler).Assembly,
// Kafka Layer
typeof(IAssetKafkaRepository).Assembly,
//typeof(IAssetKafkaRepository).Assembly,

typeof(IPersonSqlServerRepository)
//typeof(IPersonSqlServerRepository)
};

services.AddMediatR(config =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0"/>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
Expand All @@ -17,6 +17,10 @@

<ItemGroup>
<ProjectReference Include="..\..\Common\NetSampleArch.Infra.CrossCutting\NetSampleArch.Infra.CrossCutting.csproj" />
<ProjectReference Include="..\..\Adapters/NetSampleArch.Adapters.SQLServer\NetSampleArch.Adapters.SQLServer.csproj"/>
<ProjectReference Include="..\..\Adapters/NetSampleArch.Adapters.SQLServer\NetSampleArch.Adapters.SQLServer.csproj" />
<ProjectReference Include="..\..\Core\NetSampleArch.Application\NetSampleArch.Application.csproj" />
<ProjectReference Include="..\..\Adapters\NetSampleArch.Adapters.Kafka\NetSampleArch.Adapters.Kafka.csproj" />
<ProjectReference Include="..\..\Adapters\NetSampleArch.Adapters.MongoDb\NetSampleArch.Adapters.MongoDb.csproj" />
<ProjectReference Include="..\NetSampleArch.Infra.CrossCutting\NetSampleArch.Infra.CrossCutting.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PersonCreatedEntry : BaseCommand
public string Address { get; set; }
public string Phone { get; set; }
public PersonCreatedEntry(string executionUser, string createdBy, DateTime createdAt,
string updatedBy, DateTime updatedAt, TimeSpan rowVersion, string name, string address, string phone)
string updatedBy, DateTime? updatedAt, TimeSpan rowVersion, string name, string address, string phone)
: base(executionUser)
{
CreatedBy = createdBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace NetSampleArch.Infra.CrossCutting.IoC
{
public static class CommonBootstraper
public static class CommonInjectionManager
{
private static string ELK_APPLICATION_PROPERTY_NAME = "NetArchSample";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.Extensions.DependencyInjection;

namespace NetSampleArch.Application.IoC
{
public static class ApplicationInjectionManager
{
public static void Inject(IServiceCollection services)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\NetSampleArch.Domain\NetSampleArch.Domain.csproj" />
<ProjectReference Include="..\..\Common\NetSampleArch.Infra.CrossCutting\NetSampleArch.Infra.CrossCutting.csproj" />
<ProjectReference Include="..\..\Common\NetSampleArch.Infra.CrossCutting.Messages\NetSampleArch.Infra.CrossCutting.Messages.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NetSampleArch.Infra.CrossCutting.Bus.Interfaces;
using NetSampleArch.Infra.CrossCutting.Configuration;
using NetSampleArch.Infra.CrossCutting.ExtensionMethods;
using NetSampleArch.Infra.CrossCutting.Messages.Internal.Commands.ReplicatePersonCreated;
using NetSampleArch.Ports.Consumers.Interfaces.Commands;
using Serilog;

Expand All @@ -15,10 +16,27 @@ public class ReplicateCreatedPersonCommandConsumer
public ReplicateCreatedPersonCommandConsumer(ILogger logger, IBus bus, Configuration configuration)
: base(logger, bus, configuration) { }

public override Task MessageReceivedAsync(ConsumeResult<Ignore, string> receivedMessage, CancellationToken cancellationToken)
public override async Task MessageReceivedAsync(ConsumeResult<Ignore, string> receivedMessage, CancellationToken cancellationToken)
{
var command = receivedMessage.Message.Value.DeserializeFromJson<ProcessExecutionReportCommand>();
return null;
var command = receivedMessage.Message.Value.DeserializeFromJson<ReplicatePersonCreatedCommand>();

await Bus.SendCommandAsync<NetSampleArch.Infra.CrossCutting.Messages.Internal.Commands.ReplicatePersonCreated.ReplicatePersonCreatedCommand, bool>(
new NetSampleArch.Infra.CrossCutting.Messages.Internal.Commands.ReplicatePersonCreated.ReplicatePersonCreatedCommand(
new Infra.CrossCutting.Messages.Internal.Commands.ReplicatePersonCreated.Models.PersonCreatedEntry
(
executionUser: nameof(ReplicateCreatedPersonCommandConsumer),
createdAt: command.Entry.CreatedAt,
createdBy: command.Entry.CreatedBy,
updatedAt: command.Entry.UpdatedAt,
updatedBy: command.Entry.UpdatedBy,
rowVersion: command.Entry.RowVersion,
name: command.Entry.Name,
address: command.Entry.Address,
phone: command.Entry.Phone
)
),
cancellationToken
).ConfigureAwait(false);
}
}
}

0 comments on commit 0bcab17

Please sign in to comment.