Skip to content

Commit

Permalink
w r
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jun 25, 2024
1 parent fbbe5ea commit 00a43df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1591,14 +1591,19 @@ R3 extensions for Blazor.

> PM> Install-Package [R3Extensions.Blazor](https://www.nuget.org/packages/R3Extensions.Blazor)
If project target is WebAssembly Blazor, import `R3Extensions.BlazorWebAssembly` instead.

> PM> Install-Package [R3Extensions.BlazorWebAssembly](https://www.nuget.org/packages/R3Extensions.BlazorWebAssembly)
```csharp
// Add this line before Build()
// for WebAssembly use AddBlazorWebAssemblyR3() instead.
builder.Services.AddBlazorR3();

var app = builder.Build();
```

When you call `AddBlazorR3` on IServiceCollection, a TimeProvider corresponding to the request scope is implicitly used and automatically marshaled to the current request. This eliminates the need for InvokeAsync when calling time-related methods within Blazor.
When you call `AddBlazorR3/AddBlazorWebAssemblyR3` on IServiceCollection, a TimeProvider corresponding to the request scope is implicitly used and automatically marshaled to the current request. This eliminates the need for InvokeAsync when calling time-related methods within Blazor.

```csharp
public partial class Counter : IDisposable
Expand Down Expand Up @@ -1626,7 +1631,7 @@ public partial class Counter : IDisposable

In this case, since all default TimeProviders are tied to the request, you must explicitly pass `TimeProvider.System` for executions that are not related to a request.

There is also a way to utilize R3 in Blazor without using `AddBlazorR3`. One method is to use `ObserveOnCurrentSynchronizationContext`.
There is also a way to utilize R3 in Blazor without using `AddBlazorR3/AddBlazorWebAssemblyR3`. One method is to use `ObserveOnCurrentSynchronizationContext`.

```csharp
subscription = Observable.Interval(TimeSpan.FromSeconds(1)) // default TimeProvider is TimeProvider.System
Expand Down
1 change: 1 addition & 0 deletions sandbox/BlazorWebAssemblyApp1/BlazorWebAssemblyApp1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions sandbox/MauiApp1/MauiApp1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>

<!-- Display name -->
<ApplicationTitle>MauiApp1</ApplicationTitle>
Expand Down

0 comments on commit 00a43df

Please sign in to comment.