Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compensation instead of TransactionScope #13

Open
wants to merge 1 commit into
base: TransactionScope-ConnectionString
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ public async Task<int> Handle(CreateOrderRequest request, CancellationToken canc

await _dbContext.SaveChangesAsync(cancellationToken);

await _publisher.Publish(new OrderCreatedNotification(order.Id, _currentUserService.Id, _currentUserService.Email), cancellationToken);
try
{
await _publisher.Publish(new OrderCreatedNotification(order.Id, _currentUserService.Id, _currentUserService.Email), cancellationToken);
}
catch (Exception e) //Compensation
{
//log exception

_dbContext.Orders.Remove(order);
await _dbContext.SaveChangesAsync(cancellationToken);

throw;
}

return order.Id;
}
Expand Down
2 changes: 0 additions & 2 deletions ModularMonolith/Shop.Tests.Unit/WorkflowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ private ServiceCollection CreateServiceProvider(IConfiguration configuration)
services.AddMediatR(assemblies);
services.AddAutoMapper(assemblies);

services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TransactionScopePipelineBehavior<,>));

services.RegisterModule<OrderDataAccessModule>(configuration);

services.RegisterModule<FrameworkModule>(configuration);
Expand Down
7 changes: 1 addition & 6 deletions ModularMonolith/Shop.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Linq;
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -54,8 +51,6 @@ public void ConfigureServices(IServiceCollection services)
services.RegisterModule<OrderContractModule>(Configuration);
services.RegisterModule<OrderUseCasesModule>(Configuration);

services.AddScoped(typeof(IPipelineBehavior<,>), typeof(TransactionScopePipelineBehavior<,>));

var sp = services.BuildServiceProvider();

var requests = sp.GetServices<IBaseRequest>();
Expand Down
25 changes: 0 additions & 25 deletions ModularMonolith/Shop.Web/Utils/TransactionScopePipelineBehavior.cs

This file was deleted.