Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tutorials #88

Merged
merged 4 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Samples/Tutorials/Aggregates/Kitchen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Kitchen
[AggregateRoot("01ad9a9f-711f-47a8-8549-43320f782a1e")]
public class Kitchen : AggregateRoot
{
int _counter;
int _ingredients = 2;

public Kitchen(EventSourceId eventSource)
: base(eventSource)
Expand All @@ -20,11 +20,12 @@ public Kitchen(EventSourceId eventSource)

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

void On(DishPrepared @event)
=> _counter++;
=> _ingredients--;
}
}
5 changes: 3 additions & 2 deletions Samples/Tutorials/Aggregates/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/csharp/

using System.Threading.Tasks;
using Dolittle.SDK;
using Dolittle.SDK.Tenancy;

namespace Kitchen
{
class Program
{
public static void Main()
public static async Task Main()
{
var client = Client
.ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6")
Expand All @@ -21,7 +22,7 @@ public static void Main()
builder.Register<Kitchen>())
.Build();

client
await client
.AggregateOf<Kitchen>("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9", _ => _.ForTenant(TenantId.Development))
.Perform(kitchen => kitchen.PrepareDish("Bean Blaster Taco", "Mr. Taco"));

Expand Down
19 changes: 11 additions & 8 deletions Samples/Tutorials/Embeddings/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Sample code for the tutorial at https://dolittle.io/tutorials/embeddings/

using System;
using System.Linq;
using System.Threading.Tasks;
using Dolittle.SDK;
using Dolittle.SDK.Tenancy;
Expand Down Expand Up @@ -41,15 +42,17 @@ await client.Embeddings
.Update(updatedEmployee.Name, updatedEmployee);
Console.WriteLine($"Updated {updatedEmployee.Name}.");

var mrTaco = client.Embeddings
var mrTaco = await client.Embeddings
.ForTenant(TenantId.Development)
.Get<Employee>("Mr. Taco");
var allEmployees = client.Embeddings
.ForTenant(TenantId.Development)
.GetAll<Employee>();
var employeeKeys = client.Embeddings
.Get<Employee>("Mr. Taco")
.ConfigureAwait(false);
Console.WriteLine($"Mr. Taco is now working at {mrTaco.State.Workplace}");

var allEmployeeNames = await client.Embeddings
.ForTenant(TenantId.Development)
.GetKeys<Employee>();
.GetKeys<Employee>()
.ConfigureAwait(false);
Console.WriteLine($"All current employees are {string.Join(",", allEmployeeNames)}");

await client.Embeddings
.ForTenant(TenantId.Development)
Expand All @@ -60,4 +63,4 @@ await client.Embeddings
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
}
}
}
}
9 changes: 5 additions & 4 deletions Samples/Tutorials/GettingStarted/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/csharp/

using System.Threading.Tasks;
using Dolittle.SDK;
using Dolittle.SDK.Tenancy;

namespace Kitchen
{
class Program
{
public static void Main()
public static async Task Main()
{
var client = Client
.ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6")
Expand All @@ -21,15 +22,15 @@ public static void Main()

var preparedTaco = new DishPrepared("Bean Blaster Taco", "Mr. Taco");

client.EventStore
await client.EventStore
.ForTenant(TenantId.Development)
.Commit(eventsBuilder =>
eventsBuilder
.CreateEvent(preparedTaco)
.FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9"));
.FromEventSource("Dolittle Tacos"));

// Blocks until the EventHandlers are finished, i.e. forever
client.Start().Wait();
}
}
}
}
19 changes: 0 additions & 19 deletions Samples/Tutorials/Projections/DishHandler.cs

This file was deleted.

10 changes: 4 additions & 6 deletions Samples/Tutorials/Projections/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public async static Task Main()
.ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6")
.WithEventTypes(eventTypes =>
eventTypes.Register<DishPrepared>())
.WithEventHandlers(builder =>
builder.RegisterEventHandler<DishHandler>())
.WithProjections(builder => {
builder.RegisterProjection<DishCounter>();
Expand All @@ -38,19 +36,19 @@ public async static Task Main()

await eventStore.Commit(_ =>
_.CreateEvent(new DishPrepared("Bean Blaster Taco", "Mr. Taco"))
.FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9"))
.FromEventSource("Dolittle Tacos"))
.ConfigureAwait(false);
await eventStore.Commit(_ =>
_.CreateEvent(new DishPrepared("Bean Blaster Taco", "Mrs. Tex Mex"))
.FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9"))
.FromEventSource("Dolittle Tacos"))
.ConfigureAwait(false);
await eventStore.Commit(_ =>
_.CreateEvent(new DishPrepared("Avocado Artillery Tortilla", "Mr. Taco"))
.FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9"))
.FromEventSource("Dolittle Tacos"))
.ConfigureAwait(false);
await eventStore.Commit(_ =>
_.CreateEvent(new DishPrepared("Chili Canon Wrap", "Mrs. Tex Mex"))
.FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9"))
.FromEventSource("Dolittle Tacos"))
.ConfigureAwait(false);

await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
Expand Down