-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
e63e22c
commit 81e1bf0
Showing
14 changed files
with
133 additions
and
208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Common.Infrastructure; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Common.Behaviours; | ||
|
||
public class TxBehaviour<TRequest, TResponse>(IDbConnectionFactory connections, ILogger<TRequest> log) : IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : notnull | ||
{ | ||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
{ | ||
log.LogInformation("Begin transaction"); | ||
var connection = await connections.OpenAsync(); | ||
var tx = await connection.BeginTransactionAsync(cancellationToken); | ||
try | ||
{ | ||
var result = await next(); | ||
await tx.CommitAsync(cancellationToken); | ||
return result; | ||
} | ||
catch (Exception e) | ||
{ | ||
log.LogError(e, "Error executing transaction"); | ||
await tx.RollbackAsync(cancellationToken); | ||
throw; | ||
} | ||
} | ||
} |
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
163 changes: 0 additions & 163 deletions
163
templates/Host/src/Host/Infrastructure/Modules/ModuleRegistration.cs
This file was deleted.
Oops, something went wrong.
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,2 +1,12 @@ | ||
@page | ||
@model Host.Pages.Index | ||
|
||
<div class="row"> | ||
<div class="col-12"> | ||
<h1>Modular Monolith</h1> | ||
<p>Modular Monolith is a project that demonstrates how to build a modular monolith application using ASP.NET Core.</p> | ||
<a href="ModularMonolithModule">Module</a> | ||
<br> | ||
<a href="Swagger">Swagger</a> | ||
</div> | ||
</div> |
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,7 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
} | ||
|
||
<div class="container"> | ||
@RenderBody() | ||
</div> |
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,3 +1,3 @@ | ||
@{ | ||
Layout = "_Layout"; | ||
Layout = "_Page"; | ||
} |
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
11 changes: 11 additions & 0 deletions
11
...ModularMonolithModule/ModularMonolithModule.Web/Pages/ModularMonolithModule/Create.cshtml
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,2 +1,13 @@ | ||
@page | ||
@model ModularMonolithModule.Create | ||
<form method="post"> | ||
<div class="mb-3"> | ||
<label class="form-label">Name</label> | ||
<input type="text" name="name" class="form-control"/> | ||
</div> | ||
<div class="mb-3"> | ||
<label class="form-label">Price</label> | ||
<input type="text" name="price" class="form-control"/> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Create</button> | ||
</form> |
6 changes: 4 additions & 2 deletions
6
...ularMonolithModule/ModularMonolithModule.Web/Pages/ModularMonolithModule/Create.cshtml.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,12 +1,14 @@ | ||
using ModularMonolithModule.Application.Commands; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ModularMonolithModule.Application.Commands; | ||
|
||
namespace ModularMonolithModule.Web.Pages.ModularMonolithModule; | ||
|
||
public class Create(IModularMonolithModule module) : PageModel | ||
{ | ||
public async Task OnPostAsync(string name, decimal price, CancellationToken cancellationToken) | ||
public async Task<RedirectToPageResult> OnPostAsync(string name, decimal price, CancellationToken cancellationToken) | ||
{ | ||
var command = new CreateWidget.Command(Guid.NewGuid(), name, price); | ||
await module.SendCommand(command, cancellationToken); | ||
return RedirectToPage(nameof(Index)); | ||
} | ||
} |
Oops, something went wrong.