Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Sep 28, 2024
1 parent 14aa000 commit 2c87092
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
5 changes: 3 additions & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export default defineConfig({
{ label: 'Streams', link: 'client/mediator/streams' },
{ label: 'Events', link: 'client/mediator/events' },
{ label: 'Request Keys', link: 'client/mediator/requestkeys' },
{ label: 'Request Contexts', link: 'client/mediator/contexts' },
{ label: 'Advanced', link: 'client/mediator/advanced' },
{ label: 'FAQ', link: 'client/mediator/faq' },
{
label: 'Middleware',
items:[
Expand All @@ -162,8 +165,6 @@ export default defineConfig({
{ label: 'ASP.NET Core', link: 'client/mediator/extensions/aspnet' }
]
},
{ label: 'Advanced', link: 'client/mediator/advanced' },
{ label: 'FAQ', link: 'client/mediator/faq' }
]
}
],
Expand Down
23 changes: 23 additions & 0 deletions src/content/docs/client/mediator/contexts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
Title: Request Context
---

Do you want to get certain bits of contextual data without having to muck up your data? For that matter, if you're using HTTP OpenApi generation, how would
you even do that? Enter `Request Contexts`. These are basically dictionaries of objects that allow middleware to set pieces of data you may be interested in.

Some Examples

* Is this data coming from the cache? If so, when is it from?
* Is this data coming from the offline store? If so, when was it last updated?
* There was an error that user notification trapped, we displayed it to the user and logged it, but maybe I want to do a little more processing on that Exception

## How to use

```csharp
IMediator mediator; // injected
var response = mediator.RequestWithContext(myRequest, CancellationToken.None);

response.Result // your result
response.Context.

```
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Events can throw exceptions. You can trap them at a global level by awaiting th
where you may want other events to complete and not be blocked by one misbehaving piece of code. Thus, we have middleware to help
deal with this in a very simple/straight forward manor.

This middleware does nothing more than log an error and `moves on`
This middleware does nothing more than log an error and `moves on`.

:::note
This middleware is installed by default with Shiny.Mediator
:::
4 changes: 4 additions & 0 deletions src/content/docs/client/mediator/requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ IMediator.Send is for `void` requests where no result is provided
IMediator.Request is for requests that provide a result. This is to prevent future issues where the contract may change between a void & result which breaks the build intentionally to let consumers know of the change.
:::

:::warning
If you use IMediator.Request and TResult implements IEvent, mediator will publish that event for you before returning to the request caller
:::

## Middleware

In our opinion, this is where Shiny Mediator really begins to shine. Layering overtop of your requests with middleware is beautiful. We offer some excellent `out of the box` middleware. Be sure to check out it [here](/client/mediator/middleware/)
Expand Down
2 changes: 2 additions & 0 deletions src/content/docs/release-notes/mediator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import RN from '../../../components/ReleaseNote.astro';
<RN type="feature">Blazor now supports offline, stream replay, and user notification middleware</RN>
<RN type="enhancement">OpenApiGenerator now allows DateOnly, TimeOnly, and Stream results</RN>
<RN type="enhancement">OpenApiGenerator offers better support for inline enums and subtypes (node based APIs)</RN>
<RN type="enhancement">Improved logging, so you can see your pipeline execution pipeline front to back</RN>
<RN type="enhancement">Request Handlers that return a result that is marked with `IEvent` will now publish it automatically</RN>
<RN type="fix">OpenApiGenerator now tacks on global namespace to all object types</RN>
<RN type="fix">Registration source generator did not default the library namespace</RN>
<RN type="fix" githubNumber={11} pr={true} contributor='osyyyS'>Shell and NRE fixes for MAUI Event Collector</RN>
Expand Down

0 comments on commit 2c87092

Please sign in to comment.