From c2457754cf1247473022569cb095a665a3cf788e Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Tue, 14 Nov 2023 11:23:13 -0600 Subject: [PATCH] Bumping to 1.11.1 --- Directory.Build.props | 2 +- .../CreateItemCommandHandler1452615242.cs | 51 +++++++++++++++ ...gratedWithOutboxCommandHandler300308296.cs | 59 +++++++++++++++++ .../ItemCreatedHandler1524072513.cs | 30 +++++++++ ...NotIntegratedWithOutboxHandler659235566.cs | 30 +++++++++ .../WolverineHandlers/POST_items_create4.cs | 63 +++++++++++++++++++ 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemCommandHandler1452615242.cs create mode 100644 src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296.cs create mode 100644 src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedHandler1524072513.cs create mode 100644 src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566.cs create mode 100644 src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/POST_items_create4.cs diff --git a/Directory.Build.props b/Directory.Build.props index 379d4f2b0..e08a27006 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -11,7 +11,7 @@ net6.0;net7.0 1570;1571;1572;1573;1574;1587;1591;1701;1702;1711;1735;0618 true - 1.11.0 + 1.11.1 $(PackageProjectUrl) true true diff --git a/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemCommandHandler1452615242.cs b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemCommandHandler1452615242.cs new file mode 100644 index 000000000..5dbb28135 --- /dev/null +++ b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemCommandHandler1452615242.cs @@ -0,0 +1,51 @@ +// +#pragma warning disable +using Microsoft.EntityFrameworkCore; + +namespace Internal.Generated.WolverineHandlers +{ + // START: CreateItemCommandHandler1452615242 + public class CreateItemCommandHandler1452615242 : Wolverine.Runtime.Handlers.MessageHandler + { + private readonly Microsoft.EntityFrameworkCore.DbContextOptions _dbContextOptions; + + public CreateItemCommandHandler1452615242(Microsoft.EntityFrameworkCore.DbContextOptions 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 + + +} + diff --git a/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296.cs b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296.cs new file mode 100644 index 000000000..eb1452b05 --- /dev/null +++ b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/CreateItemWithDbContextNotIntegratedWithOutboxCommandHandler300308296.cs @@ -0,0 +1,59 @@ +// +#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 + * 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(); + // 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 + + +} + diff --git a/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedHandler1524072513.cs b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedHandler1524072513.cs new file mode 100644 index 000000000..9aad3d57f --- /dev/null +++ b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedHandler1524072513.cs @@ -0,0 +1,30 @@ +// +#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 + + +} + diff --git a/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566.cs b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566.cs new file mode 100644 index 000000000..29278cb2b --- /dev/null +++ b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/ItemCreatedInDbContextNotIntegratedWithOutboxHandler659235566.cs @@ -0,0 +1,30 @@ +// +#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 + + +} + diff --git a/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/POST_items_create4.cs b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/POST_items_create4.cs new file mode 100644 index 000000000..366531a68 --- /dev/null +++ b/src/Samples/EFCoreSample/ItemService/Internal/Generated/WolverineHandlers/POST_items_create4.cs @@ -0,0 +1,63 @@ +// +#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 _dbContextOptions; + private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime; + + public POST_items_create4(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Microsoft.EntityFrameworkCore.DbContextOptions 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(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 + + +} +