Skip to content

Commit

Permalink
Update exercise README that contains ViewModelComposition code
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBoike committed Oct 31, 2024
1 parent 21df202 commit 39290cd
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions exercises/01-composite-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,20 @@ In the `Divergent.Finance.ViewModelComposition` project, add a new class named `
Add the following code to the class

```csharp
using System.Net.Http;
using Divergent.Sales.ViewModelComposition.Events;
using ITOps.Json;
using ITOps.ViewModelComposition;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using System;
using System.Net.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceComposer.AspNetCore;

namespace Divergent.Finance.ViewModelComposition;

public class OrdersLoadedSubscriber : ISubscribeToCompositionEvents
public class OrdersLoadedSubscriber : ICompositionEventsSubscriber
{
// Very simple matching for the purpose of the exercise.
public bool Matches(RouteData routeData, string httpMethod) =>
HttpMethods.IsGet(httpMethod)
&& string.Equals((string)routeData.Values["controller"], "orders", StringComparison.OrdinalIgnoreCase)
&& !routeData.Values.ContainsKey("id");

public void Subscribe(IPublishCompositionEvents publisher)
[HttpGet("/orders")]
public void Subscribe(ICompositionEventsPublisher publisher)
{
publisher.Subscribe<OrdersLoaded>(async (pageViewModel, ordersLoaded, routeData, query) =>
publisher.Subscribe<OrdersLoaded>(async (ordersLoaded, httpRequest) =>
{
var orderIds = string.Join(",", ordersLoaded.OrderViewModelDictionary.Keys);

Expand Down

0 comments on commit 39290cd

Please sign in to comment.