Skip to content

Commit

Permalink
Minor fixes to example
Browse files Browse the repository at this point in the history
  • Loading branch information
mhelleborg committed Oct 24, 2023
1 parent 07e72b3 commit 09da8de
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Linq;
using Dolittle.SDK.Aggregates;
using Kitchen;
using Machine.Specifications;

namespace Specs.Kitchen.for_Kitchen.when_preparing_dish.in_one_operation;
Expand Down
3 changes: 1 addition & 2 deletions Samples/ASP.NET/Customers/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using Dolittle.SDK.Aggregates;
using Dolittle.SDK.Events;
using Microsoft.Extensions.Logging;
Expand All @@ -23,6 +22,6 @@ public Customer(EventSourceId eventSource, ILogger<Customer> logger)
public void EatDish(string dish)
{
Apply(new DishEaten(dish, Name));
_logger.LogInformation("Customer {Name} is eating {Dish}.", Name, dish);
_logger.LogInformation("Customer {Name} is eating {Dish}", Name, dish);
}
}
10 changes: 5 additions & 5 deletions Samples/ASP.NET/DishEater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
using Dolittle.SDK.Events.Handling;
using Microsoft.Extensions.Logging;

[EventHandler("86dd35ee-cd28-48d9-a0cd-cb2aa11851cb")]
public class DishEater
[EventHandler("86dd35ee-cd28-48d9-a0cd-cb2aa11851cc", partitioned:false)]
public class DishEater2
{
readonly ILogger<DishEater> _logger;
readonly ILogger<DishEater2> _logger;

public DishEater(ILogger<DishEater> logger)
public DishEater2(ILogger<DishEater2> logger)
{
_logger = logger;
}

public void Handle(DishEaten @event, EventContext ctx)
{
_logger.LogInformation($"{ctx.EventSourceId} has eaten {@event.Dish}. Yummm!");
_logger.LogInformation("{CtxEventSourceId} has eaten unpartitioned {EventDish}. Yummm!", ctx.EventSourceId, @event.Dish);
}
}
2 changes: 0 additions & 2 deletions Samples/ASP.NET/DishServer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) Dolittle. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Threading.Tasks;
using Customers;
using DnsClient.Internal;
using Dolittle.SDK.Aggregates;
using Dolittle.SDK.Events;
using Dolittle.SDK.Events.Handling;
Expand Down
9 changes: 8 additions & 1 deletion Samples/ASP.NET/Kitchen/Kitchen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ public Kitchen(EventSourceId eventSource)

public void PrepareDish(string chef, string dish)
{
if (_ingredients <= 0) throw new Exception($"Kitchen {Name} has run out of ingredients, sorry!");
if (_ingredients <= 0) throw new OutOfIngredients($"Kitchen {Name} has run out of ingredients, sorry!");
Apply(new DishPrepared(dish, chef));
Console.WriteLine($"Kitchen {EventSourceId} prepared a {dish}, there are {_ingredients} ingredients left.");
}

void On(DishPrepared @event)
=> _ingredients--;
}

public class OutOfIngredients : Exception
{
public OutOfIngredients(string message) : base(message)
{
}
}
17 changes: 12 additions & 5 deletions Samples/ASP.NET/Kitchen/KitchenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ public KitchenController(IAggregateOf<Kitchen> kitchen)
[HttpPost("prepare")]
public async Task<IActionResult> Prepare([FromBody] PrepareDish cmd)
{
await _kitchen
.Get(cmd.Kitchen)
.Perform(_ => _.PrepareDish(cmd.Chef, cmd.Dish))
.ConfigureAwait(false);
return Ok();
try
{
await _kitchen
.Get(cmd.Kitchen)
.Perform(_ => _.PrepareDish(cmd.Chef, cmd.Dish))
.ConfigureAwait(false);
return Ok();
}
catch (AggregateRootOperationFailed e) when(e.InnerException is OutOfIngredients)
{
return StatusCode(400, e.InnerException.Message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Dolittle.SDK.DependencyInversion;
using Dolittle.SDK.Tenancy;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

public interface ITenantScopedTransientService : IDisposable
Expand Down

0 comments on commit 09da8de

Please sign in to comment.