Skip to content

Commit 4128277

Browse files
committed
doc: update Fusion-Cheat-Sheet.md
1 parent d0fd9a8 commit 4128277

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

docs/tutorial/Fusion-Cheat-Sheet.md

+19-15
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class CartService : ICartService
2323
// The method must be virtual + return Task<T>
2424
public virtual async Task<List<Order>> GetOrders(long cartId, CancellationToken cancellationToken)
2525
{
26-
// ...
26+
// Implementation goes here
2727
}
2828
}
2929
```
@@ -81,20 +81,20 @@ public interface ICartClientDef
8181

8282
Configure Fusion client (this has to be done once in a code that configures client-side `IServiceProvider`):
8383
```cs
84-
var baseUri = new Uri("http://localhost:5005");
85-
var apiBaseUri = new Uri($"{baseUri}api/");
86-
87-
var fusion = services.AddFusion();
88-
fusion.AddRestEaseClient(
89-
client => {
90-
client.ConfigureWebSocketChannel(_ => new() { BaseUri = baseUri });
91-
client.ConfigureHttpClient((_, name, o) => {
92-
var isFusionClient = (name ?? "").StartsWith("Stl.Fusion");
93-
var clientBaseUri = isFusionClient ? baseUri : apiBaseUri;
94-
o.HttpClientActions.Add(httpClient => httpClient.BaseAddress = clientBaseUri);
95-
});
96-
client.AddReplicaService<ITodoService, ITodoClientDef>();
84+
var baseUri = new Uri("http://localhost:5005");
85+
var apiBaseUri = new Uri($"{baseUri}api/");
86+
87+
var fusion = services.AddFusion();
88+
fusion.AddRestEaseClient(
89+
client => {
90+
client.ConfigureWebSocketChannel(_ => new() { BaseUri = baseUri });
91+
client.ConfigureHttpClient((_, name, o) => {
92+
var isFusionClient = (name ?? "").StartsWith("Stl.Fusion");
93+
var clientBaseUri = isFusionClient ? baseUri : apiBaseUri;
94+
o.HttpClientActions.Add(httpClient => httpClient.BaseAddress = clientBaseUri);
9795
});
96+
client.AddReplicaService<ITodoService, ITodoClientDef>();
97+
});
9898
```
9999

100100
Register Replica Service:
@@ -204,7 +204,7 @@ Capture:
204204
var computed = await Computed.Capture(ct => service.ComputeMethod(args, ct), cancellationToken);
205205
```
206206

207-
Check its state:
207+
Check whether `IComputed` is still consistent:
208208
```cs
209209
if (computed.IsConsistent()) {
210210
// ...
@@ -213,6 +213,10 @@ if (computed.IsConsistent()) {
213213

214214
Await for invalidation:
215215
```cs
216+
// Always pass CancellationToken here, otherwise you'll
217+
// end up with a memory leak due to growing number of
218+
// event handler registrations. They'll be gone on
219+
// invalidation, of course, but what if it never happens?
216220
await computed.WhenInvalidated(cancellationToken);
217221
// Or
218222
computed.Invalidated += c => Console.WriteLine("Invalidated!");

0 commit comments

Comments
 (0)