Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
lghinet committed Nov 24, 2023
1 parent 8a8f8a8 commit 14d9d8a
Show file tree
Hide file tree
Showing 33 changed files with 1,210 additions and 1,221 deletions.
77 changes: 38 additions & 39 deletions dependencies.props
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
<Project>
<PropertyGroup Label="Package Versions">
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
<MediatRPackageVersion>11.1.0</MediatRPackageVersion>
<MediatRContractsPackageVersion>1.0.1</MediatRContractsPackageVersion>
<MediatRExtensionsMicrosoftDIPackageVersion>11.0.0</MediatRExtensionsMicrosoftDIPackageVersion>
<ScrutorPackageVersion>3.3.0</ScrutorPackageVersion>
<BenchmarkDotNetPackageVersion>0.13.1</BenchmarkDotNetPackageVersion>
<MoqPackageVersion>4.16.1</MoqPackageVersion>
<XunitPackageVersion>2.4.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.4.3</XunitRunnerVisualStudioPackageVersion>
<CoverletCollectorPackageVersion>3.1.0</CoverletCollectorPackageVersion>
<MicrosoftNetTestSdkPackageVersion>17.0.0</MicrosoftNetTestSdkPackageVersion>
<FsUnitPackageVersion>4.1.0</FsUnitPackageVersion>
<FluentAssertionsPackageVersion>6.3.0</FluentAssertionsPackageVersion>
<MicrosoftDataSqlClientPackageVersion>5.0.1</MicrosoftDataSqlClientPackageVersion>
<MicrosoftExtensionsPackagesVersion>7.0.0</MicrosoftExtensionsPackagesVersion>
<MicrosoftEntityFrameworkPackagesVersion>7.0.0</MicrosoftEntityFrameworkPackagesVersion>
<MicrosoftCSharpPackageVersion>4.7.0</MicrosoftCSharpPackageVersion>
<OpenTelemetryCorePackageVersion>1.5.0</OpenTelemetryCorePackageVersion>
<OpenTelemetryExtensionsHostingPackageVersion>1.5.0</OpenTelemetryExtensionsHostingPackageVersion>
<OpenTelemetryExtensionsPropagatorsPackageVersion>1.5.0</OpenTelemetryExtensionsPropagatorsPackageVersion>
<OpenTelemetryInstrumentationAspNetCorePackageVersion>1.0.0-rc9.14</OpenTelemetryInstrumentationAspNetCorePackageVersion>
<OpenTelemetryInstrumentationEFCorePackageVersion>1.0.0-beta.7</OpenTelemetryInstrumentationEFCorePackageVersion>
<OpenTelemetryInstrumentationHttpPackageVersion>1.0.0-rc9.14</OpenTelemetryInstrumentationHttpPackageVersion>
<OpenTelemetryInstrumentationRuntimePackageVersion>1.5.0</OpenTelemetryInstrumentationRuntimePackageVersion>
<OpenTelemetryExporterPrometheusHttpListenerPackageVersion>1.5.0-rc.1</OpenTelemetryExporterPrometheusHttpListenerPackageVersion>
<OpenTelemetryExporterPrometheusAspnetCorePackageVersion>1.5.0-rc.1</OpenTelemetryExporterPrometheusAspnetCorePackageVersion>
<PollyVersion>7.2.2</PollyVersion>
<SerilogPackageVersion>2.10.0</SerilogPackageVersion>
<SerilogExtensionsLoggingPackageVersion>3.1.0</SerilogExtensionsLoggingPackageVersion>
<SerilogSinksConsole>4.0.1</SerilogSinksConsole>
<SerilogSinksMSSqlServerPackageVersion>5.6.1</SerilogSinksMSSqlServerPackageVersion>
<SerilogAspNetCorePackageVersion>4.1.0</SerilogAspNetCorePackageVersion>
<AutoMapperPackageVersion>12.0.0</AutoMapperPackageVersion>
<NJsonSchemaPackageVersion>10.6.6</NJsonSchemaPackageVersion>
<AutoFixturePackageVersion>4.17.0</AutoFixturePackageVersion>
<JaegerPackageVersion>1.0.3</JaegerPackageVersion>
<SystemIdentityModelTokensJwtPackageVersion>6.15.0</SystemIdentityModelTokensJwtPackageVersion>
</PropertyGroup>
<PropertyGroup Label="Package Versions">
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
<MediatRPackageVersion>12.2.0</MediatRPackageVersion>
<MediatRContractsPackageVersion>2.0.1</MediatRContractsPackageVersion>
<ScrutorPackageVersion>3.3.0</ScrutorPackageVersion>
<BenchmarkDotNetPackageVersion>0.13.1</BenchmarkDotNetPackageVersion>
<MoqPackageVersion>4.20.69</MoqPackageVersion>
<XunitPackageVersion>2.4.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.4.3</XunitRunnerVisualStudioPackageVersion>
<CoverletCollectorPackageVersion>3.1.0</CoverletCollectorPackageVersion>
<MicrosoftNetTestSdkPackageVersion>17.0.0</MicrosoftNetTestSdkPackageVersion>
<FsUnitPackageVersion>4.1.0</FsUnitPackageVersion>
<FluentAssertionsPackageVersion>6.3.0</FluentAssertionsPackageVersion>
<MicrosoftDataSqlClientPackageVersion>5.0.1</MicrosoftDataSqlClientPackageVersion>
<MicrosoftExtensionsPackagesVersion>8.0.0</MicrosoftExtensionsPackagesVersion>
<MicrosoftEntityFrameworkPackagesVersion>8.0.0</MicrosoftEntityFrameworkPackagesVersion>
<MicrosoftCSharpPackageVersion>4.7.0</MicrosoftCSharpPackageVersion>
<OpenTelemetryCorePackageVersion>1.5.0</OpenTelemetryCorePackageVersion>
<OpenTelemetryExtensionsHostingPackageVersion>1.5.0</OpenTelemetryExtensionsHostingPackageVersion>
<OpenTelemetryExtensionsPropagatorsPackageVersion>1.5.0</OpenTelemetryExtensionsPropagatorsPackageVersion>
<OpenTelemetryInstrumentationAspNetCorePackageVersion>1.0.0-rc9.14</OpenTelemetryInstrumentationAspNetCorePackageVersion>
<OpenTelemetryInstrumentationEFCorePackageVersion>1.0.0-beta.7</OpenTelemetryInstrumentationEFCorePackageVersion>
<OpenTelemetryInstrumentationHttpPackageVersion>1.0.0-rc9.14</OpenTelemetryInstrumentationHttpPackageVersion>
<OpenTelemetryInstrumentationRuntimePackageVersion>1.5.0</OpenTelemetryInstrumentationRuntimePackageVersion>
<OpenTelemetryExporterPrometheusHttpListenerPackageVersion>1.5.0-rc.1</OpenTelemetryExporterPrometheusHttpListenerPackageVersion>
<OpenTelemetryExporterPrometheusAspnetCorePackageVersion>1.5.0-rc.1</OpenTelemetryExporterPrometheusAspnetCorePackageVersion>
<PollyVersion>7.2.2</PollyVersion>
<SerilogPackageVersion>2.10.0</SerilogPackageVersion>
<SerilogExtensionsLoggingPackageVersion>3.1.0</SerilogExtensionsLoggingPackageVersion>
<SerilogSinksConsole>4.0.1</SerilogSinksConsole>
<SerilogSinksMSSqlServerPackageVersion>5.6.1</SerilogSinksMSSqlServerPackageVersion>
<SerilogAspNetCorePackageVersion>4.1.0</SerilogAspNetCorePackageVersion>
<AutoMapperPackageVersion>12.0.0</AutoMapperPackageVersion>
<NJsonSchemaPackageVersion>10.6.6</NJsonSchemaPackageVersion>
<AutoFixturePackageVersion>4.17.0</AutoFixturePackageVersion>
<JaegerPackageVersion>1.0.3</JaegerPackageVersion>
<SystemIdentityModelTokensJwtPackageVersion>6.15.0</SystemIdentityModelTokensJwtPackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,28 @@ public ContractCommandHandlers(IEventSourcedRepository<Contract> repository, Con
_logger = logger;
}

public async Task<Unit> Handle(CreateContract command, CancellationToken cancellationToken)
public async Task Handle(CreateContract command, CancellationToken cancellationToken)
{
var contract = new Contract(command.ClientId);
await _repository.SaveAsync(contract, cancellationToken);
_domainMetrics.ContractCreated();

return Unit.Value;
}

public async Task<Unit> Handle(AddContractLine command, CancellationToken cancellationToken)
public async Task Handle(AddContractLine command, CancellationToken cancellationToken)
{
var contract = await _repository.GetByIdAsync(command.ContractId, cancellationToken);
contract.AddContractLine(command.Product, command.Price, command.Quantity);
await _repository.SaveAsync(contract, cancellationToken);

return Unit.Value;
}

public async Task<Unit> Handle(ValidateContract command, CancellationToken cancellationToken)
public async Task Handle(ValidateContract command, CancellationToken cancellationToken)
{
_logger.LogInformation("Validating contract");

var contract = await _repository.GetByIdAsync(command.ContractId, cancellationToken);
contract.Validate();
await _repository.SaveAsync(contract, cancellationToken);
_domainMetrics.ContractValidated();

return Unit.Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRExtensionsMicrosoftDIPackageVersion)" />
<PackageReference Include="MediatR" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(MicrosoftExtensionsPackagesVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public static async Task Main(string[] args)
})
.ConfigureServices((hostingContext, services) =>
{
services.AddMediatR(typeof(ContractCommandHandlers).Assembly);

services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<ContractCommandHandlers>());

var transport = hostingContext.Configuration.GetValue("Messaging:Transport", "NATS");
if (transport.Equals("NATS", StringComparison.InvariantCultureIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.

using MediatR;
using NBB.Data.Abstractions;
using NBB.Invoices.Domain.InvoiceAggregate;
using MediatR;
using NBB.Data.Abstractions;
using NBB.Invoices.Domain.InvoiceAggregate;
using NBB.Invoices.PublishedLanguage;
using System.Threading;
using System.Threading.Tasks;

namespace NBB.Invoices.Application.CommandHandlers
{
public class CreateInvoiceCommandHandler : IRequestHandler<CreateInvoice>
{
private readonly ICrudRepository<Invoice> _repository;
public CreateInvoiceCommandHandler(ICrudRepository<Invoice> repository)
{
this._repository = repository;
}

public async Task<Unit> Handle(CreateInvoice command, CancellationToken cancellationToken)
{
var invoice = new Invoice(command.ClientId, command.ContractId, command.Amount);
await _repository.AddAsync(invoice, cancellationToken);
await _repository.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}
}
using System.Threading;
using System.Threading.Tasks;

namespace NBB.Invoices.Application.CommandHandlers
{
public class CreateInvoiceCommandHandler : IRequestHandler<CreateInvoice>
{
private readonly ICrudRepository<Invoice> _repository;
public CreateInvoiceCommandHandler(ICrudRepository<Invoice> repository)
{
this._repository = repository;
}

public async Task Handle(CreateInvoice command, CancellationToken cancellationToken)
{
var invoice = new Invoice(command.ClientId, command.ContractId, command.Amount);
await _repository.AddAsync(invoice, cancellationToken);
await _repository.SaveChangesAsync(cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MarkInvoiceAsPayedCommandHandler(ICrudRepository<Invoice> repository)
this._repository = repository;
}

public async Task<Unit> Handle(MarkInvoiceAsPayed command, CancellationToken cancellationToken)
public async Task Handle(MarkInvoiceAsPayed command, CancellationToken cancellationToken)
{
var invoice = await _repository.GetByIdAsync(command.InvoiceId, cancellationToken);
if (invoice != null)
Expand All @@ -27,7 +27,6 @@ public async Task<Unit> Handle(MarkInvoiceAsPayed command, CancellationToken can

await _repository.SaveChangesAsync(cancellationToken);
}
return Unit.Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ProcessInvoiceCommandHandler(ICrudRepository<Invoice> invocieRepository,
this._invoiceLockRepository = invoiceLockRepository;
}

public Task<Unit> Handle(ProcessInvoice command, CancellationToken cancellationToken)
public Task Handle(ProcessInvoice command, CancellationToken cancellationToken)
=> UsingInvoiceLock(command.InvoiceId, lockTimeoutMs: 10000, async () =>
{
var invoice = await _invocieRepository.GetByIdAsync(command.InvoiceId, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRExtensionsMicrosoftDIPackageVersion)" />
<PackageReference Include="MediatR" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(MicrosoftExtensionsPackagesVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static async Task Main(string[] args)
})
.ConfigureServices((hostingContext, services) =>
{
services.AddMediatR(typeof(CreateInvoiceCommandHandler).Assembly);
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<CreateInvoiceCommandHandler>());

services.AddMessageBus().AddNatsTransport(hostingContext.Configuration);
services.AddInvoicesWriteDataAccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRExtensionsMicrosoftDIPackageVersion)" />
<PackageReference Include="MediatR" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(MicrosoftExtensionsPackagesVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static async Task Main(string[] args)
})
.ConfigureServices((hostingContext, services) =>
{
services.AddMediatR(typeof(Program).Assembly);
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Program>());

services.AddMessageBus().AddNatsTransport(hostingContext.Configuration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ public CreatePayableCommandHandler(ICrudRepository<Payable> repository)
_repository = repository;
}

public async Task<Unit> Handle(CreatePayable command, CancellationToken cancellationToken)
public async Task Handle(CreatePayable command, CancellationToken cancellationToken)
{
var payable = new Payable(command.ClientId, command.Amount, command.InvoiceId, command.ContractId);
await _repository.AddAsync(payable, cancellationToken);
await _repository.SaveChangesAsync(cancellationToken);

return Unit.Value;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.

using MediatR;
using NBB.Data.Abstractions;
using NBB.Payments.Domain.PayableAggregate;
using MediatR;
using NBB.Data.Abstractions;
using NBB.Payments.Domain.PayableAggregate;
using NBB.Payments.PublishedLanguage;
using System.Threading;
using System.Threading.Tasks;

namespace NBB.Payments.Application.CommandHandlers
{
public class PayPayableCommandHandler : IRequestHandler<PayPayable>
{
private readonly ICrudRepository<Payable> _repository;

public PayPayableCommandHandler(ICrudRepository<Payable> repository)
{
_repository = repository;
}


public async Task<Unit> Handle(PayPayable command, CancellationToken cancellationToken)
{
var payable = await _repository.GetByIdAsync(command.PayableId, cancellationToken);
if (payable != null)
{
payable.Pay();
await _repository.SaveChangesAsync(cancellationToken);
}

return Unit.Value;
}
}
}
using System.Threading;
using System.Threading.Tasks;

namespace NBB.Payments.Application.CommandHandlers
{
public class PayPayableCommandHandler : IRequestHandler<PayPayable>
{
private readonly ICrudRepository<Payable> _repository;

public PayPayableCommandHandler(ICrudRepository<Payable> repository)
{
_repository = repository;
}


public async Task Handle(PayPayable command, CancellationToken cancellationToken)
{
var payable = await _repository.GetByIdAsync(command.PayableId, cancellationToken);
if (payable != null)
{
payable.Pay();
await _repository.SaveChangesAsync(cancellationToken);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="$(MediatRExtensionsMicrosoftDIPackageVersion)" />
<PackageReference Include="MediatR" Version="$(MediatRPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsPackagesVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="$(MicrosoftExtensionsPackagesVersion)" />
Expand Down
Loading

0 comments on commit 14d9d8a

Please sign in to comment.