Skip to content

Commit

Permalink
Removed Marten references
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed May 2, 2024
1 parent 46acc44 commit b1adfe9
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 34 deletions.
Expand Up @@ -5,9 +5,9 @@ namespace ApplicationLogic.Marten.Core.Marten;

public static class DocumentSessionExtensions
{
public static Task Add<T>(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct)
where T : class
=> throw new NotImplementedException("Document Session Extensions not implemented!");
public static Task Add<T>(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct)
where T : class, IAggregate =>
throw new NotImplementedException("Document Session Extensions not implemented!");

public static Task Add<T>(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct)
where T : class
Expand Down
Expand Up @@ -25,8 +25,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a
{
var shoppingCartId = CombGuidIdGeneration.NewGuid();
await session.Add<MutableShoppingCart>(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct);
await session.Add(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct);
return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId);
}
Expand Down
Expand Up @@ -6,12 +6,10 @@ namespace OptimisticConcurrency.Core.Marten;

public static class DocumentSessionExtensions
{
public static Task Add<T>(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct)
where T : class
{
documentSession.Events.StartStream<T>(id, @event);
return documentSession.SaveChangesAsync(token: ct);
}
public static Task Add<T>(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct)
where T : class, IAggregate =>
documentSession.Add<T>(id, aggregate.DequeueUncommittedEvents(), ct);


public static Task Add<T>(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct)
where T : class
Expand Down
Expand Up @@ -28,8 +28,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a
{
var shoppingCartId = CombGuidIdGeneration.NewGuid();
await session.Add<MutableShoppingCart>(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct);
await session.Add(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct);
return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId);
}
Expand Down
Expand Up @@ -6,12 +6,9 @@ namespace ApplicationLogic.Marten.Core.Marten;

public static class DocumentSessionExtensions
{
public static Task Add<T>(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct)
where T : class
{
documentSession.Events.StartStream<T>(id, @event);
return documentSession.SaveChangesAsync(token: ct);
}
public static Task Add<T>(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct)
where T : class, IAggregate =>
documentSession.Add<T>(id, aggregate.DequeueUncommittedEvents(), ct);

public static Task Add<T>(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct)
where T : class
Expand All @@ -35,10 +32,10 @@ CancellationToken ct
Action<T> handle,
CancellationToken ct
) where T : class, IAggregate =>
documentSession.Events.WriteToAggregate<T>(id, stream =>
documentSession.GetAndUpdate<T>(id, state =>
{
var aggregate = stream.Aggregate ?? throw NotFoundException.For<T>(id);
handle(aggregate);
stream.AppendMany(aggregate.DequeueUncommittedEvents());
handle(state);
var events = state.DequeueUncommittedEvents();
return events;
}, ct);
}
Expand Up @@ -25,8 +25,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a
{
var shoppingCartId = CombGuidIdGeneration.NewGuid();
await session.Add<MutableShoppingCart>(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct);
await session.Add(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct);
return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId);
}
Expand Down
Expand Up @@ -9,10 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Marten.CommandLine" Version="7.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Marten.AspNetCore" Version="7.8.0" />
<PackageReference Include="Marten" Version="7.8.0" />
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="23.2.1"/>
</ItemGroup>

<ItemGroup>
Expand Down
Expand Up @@ -2,9 +2,7 @@
using ApplicationLogic.EventStoreDB.Immutable.ShoppingCarts;
using ApplicationLogic.EventStoreDB.Mixed.ShoppingCarts;
using ApplicationLogic.EventStoreDB.Mutable.ShoppingCarts;
using Marten;
using Microsoft.AspNetCore.Diagnostics;
using Oakton;

var builder = WebApplication.CreateBuilder(args);

Expand Down
Expand Up @@ -6,9 +6,9 @@ namespace OptimisticConcurrency.Core.Marten;

public static class DocumentSessionExtensions
{
public static Task<int> Add<T>(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct)
where T : class =>
documentSession.Add<T>(id, [@event], ct);
public static Task<int> Add<T>(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct)
where T : class, IAggregate =>
documentSession.Add<T>(id, aggregate.DequeueUncommittedEvents(), ct);

public static async Task<int> Add<T>(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct)
where T : class
Expand Down
Expand Up @@ -31,7 +31,7 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a
var shoppingCartId = CombGuidIdGeneration.NewGuid();
var nextExpectedVersion = await session.Add<MutableShoppingCart>(shoppingCartId,
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct);
MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct);
context.SetResponseEtag(nextExpectedVersion);
Expand Down

0 comments on commit b1adfe9

Please sign in to comment.