-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
763630f
commit c245775
Showing
6 changed files
with
234 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
...le/ItemService/Internal/Generated/WolverineHandlers/CreateItemCommandHandler1452615242.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 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: CreateItemCommandHandler1452615242 | ||
public class CreateItemCommandHandler1452615242 : Wolverine.Runtime.Handlers.MessageHandler | ||
{ | ||
private readonly Microsoft.EntityFrameworkCore.DbContextOptions<ItemService.ItemsDbContext> _dbContextOptions; | ||
|
||
public CreateItemCommandHandler1452615242(Microsoft.EntityFrameworkCore.DbContextOptions<ItemService.ItemsDbContext> dbContextOptions) | ||
{ | ||
_dbContextOptions = dbContextOptions; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | ||
{ | ||
await using var itemsDbContext = new ItemService.ItemsDbContext(_dbContextOptions); | ||
// The actual message body | ||
var createItemCommand = (ItemService.CreateItemCommand)context.Envelope.Message; | ||
|
||
|
||
// Enroll the DbContext & IMessagingContext in the outgoing Wolverine outbox transaction | ||
var envelopeTransaction = Wolverine.EntityFrameworkCore.WolverineEntityCoreExtensions.BuildTransaction(itemsDbContext, context); | ||
await context.EnlistInOutboxAsync(envelopeTransaction); | ||
|
||
// The actual message execution | ||
var outgoing1 = ItemService.CreateItemCommandHandler.Handle(createItemCommand, itemsDbContext); | ||
|
||
|
||
// Outgoing, cascaded message | ||
await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); | ||
|
||
|
||
// Added by EF Core Transaction Middleware | ||
var result_of_SaveChangesAsync = await itemsDbContext.SaveChangesAsync(cancellation).ConfigureAwait(false); | ||
|
||
// If we have separate context for outbox and application, then we need to manually commit the transaction | ||
if (envelopeTransaction is Wolverine.EntityFrameworkCore.Internals.RawDatabaseEnvelopeTransaction rawTx) { await rawTx.CommitAsync(); } | ||
} | ||
|
||
} | ||
|
||
// END: CreateItemCommandHandler1452615242 | ||
|
||
|
||
} | ||
|
59 changes: 59 additions & 0 deletions
59
...olverineHandlers/CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296.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,59 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Lamar; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296 | ||
public class CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296 : Wolverine.Runtime.Handlers.MessageHandler | ||
{ | ||
private readonly Lamar.IContainer _rootContainer; | ||
|
||
public CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296(Lamar.IContainer rootContainer) | ||
{ | ||
_rootContainer = rootContainer; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | ||
{ | ||
await using var nestedContainer = (Lamar.IContainer)_rootContainer.GetNestedContainer(); | ||
|
||
/* | ||
* Dependency: Lambda Factory of DbContextOptions<ItemService.ItemsDbContextWithoutOutbox> | ||
* The scoping is Scoped, so a Lambda registration requires | ||
* the usage of a nested container for resolution for correct scoping. | ||
* A formal factory provider may be an alternative | ||
*/ | ||
var itemsDbContextWithoutOutbox = nestedContainer.GetInstance<ItemService.ItemsDbContextWithoutOutbox>(); | ||
// The actual message body | ||
var createItemWithDbContextNotIntegratedWithOutboxCommand = (ItemService.CreateItemWithDbContextNotIntegratedWithOutboxCommand)context.Envelope.Message; | ||
|
||
|
||
// Enroll the DbContext & IMessagingContext in the outgoing Wolverine outbox transaction | ||
var envelopeTransaction = Wolverine.EntityFrameworkCore.WolverineEntityCoreExtensions.BuildTransaction(itemsDbContextWithoutOutbox, context); | ||
await context.EnlistInOutboxAsync(envelopeTransaction); | ||
|
||
// The actual message execution | ||
var outgoing1 = ItemService.CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler.Handle(createItemWithDbContextNotIntegratedWithOutboxCommand, itemsDbContextWithoutOutbox); | ||
|
||
|
||
// Outgoing, cascaded message | ||
await context.EnqueueCascadingAsync(outgoing1).ConfigureAwait(false); | ||
|
||
|
||
// Added by EF Core Transaction Middleware | ||
var result_of_SaveChangesAsync = await itemsDbContextWithoutOutbox.SaveChangesAsync(cancellation).ConfigureAwait(false); | ||
|
||
// If we have separate context for outbox and application, then we need to manually commit the transaction | ||
if (envelopeTransaction is Wolverine.EntityFrameworkCore.Internals.RawDatabaseEnvelopeTransaction rawTx) { await rawTx.CommitAsync(); } | ||
} | ||
|
||
} | ||
|
||
// END: CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296 | ||
|
||
|
||
} | ||
|
30 changes: 30 additions & 0 deletions
30
...reSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedHandler1524072513.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,30 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: ItemCreatedHandler1524072513 | ||
public class ItemCreatedHandler1524072513 : Wolverine.Runtime.Handlers.MessageHandler | ||
{ | ||
|
||
|
||
public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | ||
{ | ||
var itemCreatedHandler = new ItemService.ItemCreatedHandler(); | ||
// The actual message body | ||
var itemCreated = (ItemService.ItemCreated)context.Envelope.Message; | ||
|
||
|
||
// The actual message execution | ||
itemCreatedHandler.Handle(itemCreated); | ||
|
||
return System.Threading.Tasks.Task.CompletedTask; | ||
} | ||
|
||
} | ||
|
||
// END: ItemCreatedHandler1524072513 | ||
|
||
|
||
} | ||
|
30 changes: 30 additions & 0 deletions
30
...erated/WolverineHandlers/ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566.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,30 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566 | ||
public class ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566 : Wolverine.Runtime.Handlers.MessageHandler | ||
{ | ||
|
||
|
||
public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | ||
{ | ||
var itemCreatedInDbContextNotIntegratedWithOutboxHandler = new ItemService.ItemCreatedInDbContextNotIntegratedWithOutboxHandler(); | ||
// The actual message body | ||
var itemCreatedInDbContextNotIntegratedWithOutbox = (ItemService.ItemCreatedInDbContextNotIntegratedWithOutbox)context.Envelope.Message; | ||
|
||
|
||
// The actual message execution | ||
itemCreatedInDbContextNotIntegratedWithOutboxHandler.Handle(itemCreatedInDbContextNotIntegratedWithOutbox); | ||
|
||
return System.Threading.Tasks.Task.CompletedTask; | ||
} | ||
|
||
} | ||
|
||
// END: ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566 | ||
|
||
|
||
} | ||
|
63 changes: 63 additions & 0 deletions
63
...mples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/POST_items_create4.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,63 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Linq; | ||
using Wolverine.Http; | ||
using Wolverine.Runtime; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: POST_items_create4 | ||
public class POST_items_create4 : Wolverine.Http.HttpHandler | ||
{ | ||
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions; | ||
private readonly Microsoft.EntityFrameworkCore.DbContextOptions<ItemService.ItemsDbContext> _dbContextOptions; | ||
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime; | ||
|
||
public POST_items_create4(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Microsoft.EntityFrameworkCore.DbContextOptions<ItemService.ItemsDbContext> dbContextOptions, Wolverine.Runtime.IWolverineRuntime wolverineRuntime) : base(wolverineHttpOptions) | ||
{ | ||
_wolverineHttpOptions = wolverineHttpOptions; | ||
_dbContextOptions = dbContextOptions; | ||
_wolverineRuntime = wolverineRuntime; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext) | ||
{ | ||
await using var itemsDbContext = new ItemService.ItemsDbContext(_dbContextOptions); | ||
var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime); | ||
|
||
// Enroll the DbContext & IMessagingContext in the outgoing Wolverine outbox transaction | ||
var envelopeTransaction = Wolverine.EntityFrameworkCore.WolverineEntityCoreExtensions.BuildTransaction(itemsDbContext, messageContext); | ||
await messageContext.EnlistInOutboxAsync(envelopeTransaction); | ||
// Reading the request body via JSON deserialization | ||
var (command, jsonContinue) = await ReadJsonAsync<ItemService.CreateItemCommand>(httpContext); | ||
if (jsonContinue == Wolverine.HandlerContinuation.Stop) return; | ||
|
||
// The actual HTTP request handler execution | ||
var itemCreated = ItemService.CreateItemEndpoint.Post(command, itemsDbContext); | ||
|
||
|
||
// Outgoing, cascaded message | ||
await messageContext.EnqueueCascadingAsync(itemCreated).ConfigureAwait(false); | ||
|
||
|
||
// Added by EF Core Transaction Middleware | ||
var result_of_SaveChangesAsync = await itemsDbContext.SaveChangesAsync(httpContext.RequestAborted).ConfigureAwait(false); | ||
|
||
// If we have separate context for outbox and application, then we need to manually commit the transaction | ||
if (envelopeTransaction is Wolverine.EntityFrameworkCore.Internals.RawDatabaseEnvelopeTransaction rawTx) { await rawTx.CommitAsync(); } | ||
// Wolverine automatically sets the status code to 204 for empty responses | ||
if (!httpContext.Response.HasStarted) httpContext.Response.StatusCode = 204; | ||
} | ||
|
||
} | ||
|
||
// END: POST_items_create4 | ||
|
||
|
||
} | ||
|