Skip to content

Commit

Permalink
Update aspnet.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Nov 9, 2024
1 parent a471318 commit 85b337b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/content/docs/client/mediator/extensions/aspnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ following;
<Steps>
1. Install Shiny.Mediator.AspNet <NugetBadge name="Shiny.Mediator.AspNet" label="Shiny.Mediator.AspNet" /> to your ASP.NET Core project.

2. On your request handler (void or result based), add `[MediatorHttpPost("OperationId", "MyRoute")]` or `[MediatorHttpPut("OperationId", "MyRoute")]` attribute to the handler.
2. On your request handler (void or result based), add `[MediatorHttpPost("OperationId", "MyRoute")]` or `[MediatorHttpPut("OperationId", "MyRoute")]` (GET & DELETE attributes also available) attribute to the handler.

```csharp
[MediatorHttpPost("TheOperationId", "MyRoute")]
Expand All @@ -40,20 +40,19 @@ following;
}
```

3. In your host startup, register your handler (or use the source generator attributes).
3. In your host startup, add the following after your build your app. Here is a full-ish sample

```csharp
services.AddSingletonAsImplementedInterfaces<MyHandler>();
```
var builder = WebApplication.CreateBuilder(args);

4. Again, in your host startup, add the following after your build your app. Here is a full-ish sample
// MAKE MEDIATOR AVAILABLE
builder.Services.AddShinyMediator();

```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddShinyMediator();
services.AddSingletonAsImplementedInterfaces<MyHandler>();
// ADD YOUR HANDLER(S)
services.AddScopeAsImplementedInterfaces<MyHandler>();
var app = builder.Build();

// ADD REGISTERED HANDLERS THAT ARE ATTRIBUTED TO THE HTTP ENDPOINTS
app.UseShinyMediatorEndpointHandlers(builder.Services);
app.Run();
```
Expand Down Expand Up @@ -87,4 +86,8 @@ public class MediatorHttpAttribute(string operationId, string uriTemplate, HttpM

:::warning
It is best to register most handlers and middleware as `Scoped` on ASP.NET Core apps
:::

:::warning
MediatorHttpGet & MediatorHttpDelete parameters can only be set on the route or querystring
:::

0 comments on commit 85b337b

Please sign in to comment.