-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boom! Can use [Edit] and IStorageAction types with RavenDb
- Loading branch information
1 parent
b7be46b
commit 0bbf7e9
Showing
8 changed files
with
162 additions
and
27 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
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,53 @@ | ||
// <auto-generated/> | ||
#pragma warning disable | ||
using Raven.Client.Documents; | ||
|
||
namespace Internal.Generated.WolverineHandlers | ||
{ | ||
// START: CreateTodoHandler1536167811 | ||
public class CreateTodoHandler1536167811 : Wolverine.Runtime.Handlers.MessageHandler | ||
{ | ||
private readonly Raven.Client.Documents.IDocumentStore _documentStore; | ||
|
||
public CreateTodoHandler1536167811(Raven.Client.Documents.IDocumentStore documentStore) | ||
{ | ||
_documentStore = documentStore; | ||
} | ||
|
||
|
||
|
||
public override async System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation) | ||
{ | ||
// The actual message body | ||
var createTodo = (Wolverine.ComplianceTests.CreateTodo)context.Envelope.Message; | ||
|
||
|
||
// Open a new document session | ||
// message context to support the outbox functionality | ||
using var asyncDocumentSession = _documentStore.OpenAsyncSession(); | ||
context.EnlistInOutbox(new Wolverine.RavenDb.Internals.RavenDbEnvelopeTransaction(asyncDocumentSession, context)); | ||
|
||
// The actual message execution | ||
var outgoing1 = Wolverine.ComplianceTests.TodoHandler.Handle(createTodo); | ||
|
||
if (outgoing1 != null) | ||
{ | ||
await asyncDocumentSession.StoreAsync(outgoing1.Entity, cancellation).ConfigureAwait(false); | ||
} | ||
|
||
|
||
// Commit any outstanding RavenDb changes | ||
await asyncDocumentSession.SaveChangesAsync(cancellation).ConfigureAwait(false); | ||
|
||
|
||
// Have to flush outgoing messages just in case Marten did nothing because of https://github.com/JasperFx/wolverine/issues/536 | ||
await context.FlushOutgoingMessagesAsync().ConfigureAwait(false); | ||
|
||
} | ||
|
||
} | ||
|
||
// END: CreateTodoHandler1536167811 | ||
|
||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
src/Persistence/RavenDbTests/using_storage_return_types_and_entity_attributes.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,46 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Raven.Client.Documents; | ||
using Wolverine; | ||
using Wolverine.ComplianceTests; | ||
using Wolverine.RavenDb; | ||
|
||
namespace RavenDbTests; | ||
|
||
[Collection("raven")] | ||
public class using_storage_return_types_and_entity_attributes : StorageActionCompliance | ||
{ | ||
private readonly DatabaseFixture _fixture; | ||
|
||
public using_storage_return_types_and_entity_attributes(DatabaseFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
protected override void configureWolverine(WolverineOptions opts) | ||
{ | ||
var store = _fixture.StartRavenStore(); | ||
|
||
// You *must* register the store after the RavenDb envelope storage | ||
opts.UseRavenDbPersistence(); | ||
opts.Services.AddSingleton(store); | ||
opts.Policies.AutoApplyTransactions(); | ||
opts.Durability.Mode = DurabilityMode.Solo; | ||
|
||
opts.CodeGeneration.ReferenceAssembly(typeof(Wolverine.RavenDb.IRavenDbOp).Assembly); | ||
} | ||
|
||
public override async Task<Todo?> Load(string id) | ||
{ | ||
var store = Host.Services.GetRequiredService<IDocumentStore>(); | ||
using var session = store.OpenAsyncSession(); | ||
return await session.LoadAsync<Todo>(id); | ||
} | ||
|
||
public override async Task Persist(Todo todo) | ||
{ | ||
var store = Host.Services.GetRequiredService<IDocumentStore>(); | ||
using var session = store.OpenAsyncSession(); | ||
await session.StoreAsync(todo); | ||
await session.SaveChangesAsync(); | ||
} | ||
} |
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
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