https://github.com/marimerllc/marimer.blazor.rendermode
https://github.com/marimerllc/marimer.blazor.rendermode
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/marimerllc/marimer.blazor.rendermode
- Owner: MarimerLLC
- License: mit
- Created: 2024-09-09T22:13:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-08T20:22:48.000Z (over 1 year ago)
- Last Synced: 2025-04-28T12:04:38.701Z (11 months ago)
- Language: C#
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Blazor Render Mode Detection
The `Marimer.Blazor.RenderMode` library provides a simple way to detect the current render mode of a Blazor application.
## Installation
You can install the library via NuGet. Run the following command for a Blazor Server project:
```
dotnet add package Marimer.Blazor.RenderMode
```
For a Blazor WebAssembly project or Razor Class Library, run the following command:
```
dotnet add package Marimer.Blazor.RenderMode.WebAssembly
```
In `Program.cs`, add the following line to register the service:
```csharp
builder.Services.AddRenderModeDetection();
```
When using a Razor Class Library that may be loaded in WebAssembly, make sure to add that registration to the client-side `Program.cs` as well.
## Usage
The library provides a `RenderModeProvider` service that you can inject into your components. The service has a single method `GetRenderMode` that returns the current render mode for the current page or component.
```csharp
@inject RenderModeProvider RenderMode
@using Marimer.Blazor.RenderMode
var mode = RenderMode.GetRenderMode(this);
@if (mode.IsInteractive() && mode.IsServer())
{
This is a server interactive Blazor page
}
else if (mode.IsWebAssembly())
{
This is a WebAssembly interactive Blazor page
}
else if (mode.IsServer() && mode.IsStreaming())
{
This is a streaming server static Blazor page
}
else
{
This is a server static Blazor page
}
```