Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Sep 23, 2024
1 parent 356a7b1 commit 7046e47
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 62 deletions.
4 changes: 3 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ export default defineConfig({
items:[
{ label: 'Introduction', link: 'server' },
{ label: 'Email', link: 'server/email' },
{ label: 'Push Management', link: 'server/push' }
{ label: 'Push Management', link: 'server/push' },
{ label: 'Entity Framework', link: 'server/ef' },
{ label: 'Web Hosting', link: 'server/webhosting' }
]
},
{
Expand Down
4 changes: 0 additions & 4 deletions src/content/docs/client/mediator/extensions/aspnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ following;
}
```

:::note
Currently - we only support `HttpPost` and `HttpPut` attributes. We will look into Get/Delete in the future
:::

3. In your host startup, register your handler (or use the source generator attributes).

```csharp
Expand Down
50 changes: 8 additions & 42 deletions src/content/docs/client/mediator/extensions/http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ add the boilerplate mediator contract and subsequent request handler, so... we f
<Steps>
1. Let's start with our mediator request contract - Notice that we have some attributes & interfaces that are specific to HTTP requests

```csharp
using Shiny.Mediator;
using Shiny.Mediator.Http;
```csharp
using Shiny.Mediator;
using Shiny.Mediator.Http;

[Http(HttpVerb.Post, "/route/{Parameter}")]
public class MyRequest : IHttpRequest<MyResponse>
Expand Down Expand Up @@ -45,7 +45,11 @@ add the boilerplate mediator contract and subsequent request handler, so... we f
{
"Mediator": {
"Http": {
"Your.Namespace": "https://yourapi.com"
"Your.Namespace.Contract": "https://yourapi.com",
// OR
"Your.Namespace.*": "https://yourapi.com"
// OR
"*": "https://yourapi.com"
}
}
}
Expand Down Expand Up @@ -112,19 +116,6 @@ public class MauiHttpRequestDecorator<TRequest, TResult>(
Just like middleware & handlers - HTTP Decorators support covariance as well
:::

## Adding Cache/Offline Support

Without a request handler to mark the functionalilty attribute markers with, the question obviously comes up about how to get things like offline, caching, & resilience on both the HTTP request. Simple... just mark the attribute on the contract itself.

```csharp
[OfflineAvailable]
[Cache]
public partial class MyRequest
{

}
```

## Generating All The Contracts and Responses

Some WebAPIs can have a large API surface with many routes, parameters, and types. Generating OpenAPI files is pretty standard these days with things like NSwag, Swashbuckle, & Refitter. Shiny Mediator can help with this as well. You can generate all the contracts and responses from an OpenAPI file or URI to an OpenAPI document.
Expand All @@ -141,28 +132,3 @@ Simply edit your csproj file that has `Shiny.Mediator` installed and add the fol
:::note
If you're setting the Uri attribute, you must still set the Include value to satisfy the ItemGroup. Also note, the use of Visible="false". This removes the registration of the msbuild variable from the IDE solution explorer.
:::

## Adding Cache/Offline Support to Generated

As shown above, adding the feature marker attributes will get you a lot of the Shiny Mediator features like caching, offline, and resilience.
However, how do you do this with the generated source code? We mark the generated classes partial, which allows you to implement additional functionality by simply adding another partial class of your own
to the same namespace.

_Generated_
```csharp
namespace SomeGeneratedRequests;
public partial class MyRequest : IHttpRequest<Response>
{
...
}
```

_Added by you_
```csharp
[OfflineAvailable]
[Cache]
public partial class MyRequest
{

}
```
20 changes: 19 additions & 1 deletion src/content/docs/client/mediator/middleware/caching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Fine grained control over caching is available with the `CacheAttribute` attribu
<Steps>
1. Install Shiny.Mediator.Caching <NugetBadge name="Shiny.Mediator.Caching" label="Shiny.Mediator.Caching" /> to your project.

2. On your request handler (result based), add `[Cache]` attribute to the handler.
2. Create your request handler - you can mark Cache here with the attribute or you can use [Configuration](./).

```csharp
[Cache]
Expand Down Expand Up @@ -66,4 +66,22 @@ public class MyContract : IRequest<SomeResponse>, ICacheControl
public bool ForceRefresh { get; set; }
public Action<ICacheEntry>? SetEntry { get; set; } // optional: allows you to set cache entry properties
}
```

### Configuration

We recommend configuring cache through Microsoft.Extensions.Configuration. Read [Configuration](./) for more information.

```json
{
"Mediator": {
"Cache": {
"My.Namespace.MyHandler": {
"Priority": "High",
"AbsoluteExpirationSeconds": 60,
"SlidingExpirationSeconds": 30
}
}
}
}
```
2 changes: 1 addition & 1 deletion src/content/docs/client/mediator/middleware/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Below is an example of essentially every configuration option we have available.
"My.Namespace.Contract": "https://otherlocalhost",
"My.Namespace.*" : "https://localhost"
},
"Performance": {
"PerformanceLogging": {
"*": {
"ErrorThresholdMilliseconds": 5000
}
Expand Down
20 changes: 19 additions & 1 deletion src/content/docs/client/mediator/middleware/offline.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,32 @@ Fine grained control over offline data is available via [Request Keys](../reques
```csharp
public class MyRequestHandler : IRequestHandler<MyRequest, IReadOnlyList<MyThingData>>
{
[Offline(true)]
[OfflineAvailable(true)]
public async Task<IReadOnlyList<MyThingData>> Handle(MyRequest request, CancellationToken cancellationToken)
{
// each return will overwrite the previous return value
}
}
```

:::note
Above is configured with the `OfflineAvailableAttribute`. You can also configure the Microsoft Extensions Configuration using the following:

```json
{
"Mediator": {
"PerformanceLogging": {
"*": {
"ErrorThresholdMilliseconds": 5000
}
}
}
}
```

For more info about configuration, see [Middleware Configuration](./)
:::

## Controlling HOW the offline data is stored

Often, there are times you want to store data based on the parameter arguments within your request. Trying to build these keys for you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
title: REQUESTS - Timed Logging
title: REQUESTS - Performance Logging
---
import { Steps } from '@astrojs/starlight/components';
import NugetBadge from '../../../../../components/NugetBadge.tsx';


Ever wanted to track and log how long your requests take to process? Maybe even have an error logged if a call is passing
a certain threshold? The `TimedLogging` middleware is designed to help you with this.
a certain threshold? The `PerformanceLogging` middleware is designed to help you with this.

Internally, the middleware will log the time it takes to process a request to your logging setup. If the error threshold is passed, it
will log an error otherwise it will log to Debug.
Expand All @@ -20,22 +20,25 @@ We recommend focusing timed logging on your most critical requests. Logging eve
In your host startup, add the following to your mediator configuration:

```csharp
services.AddShinyMediator(cfg => cfg.UseTimedLogging());
services.AddShinyMediator(cfg => cfg.UsePerformanceLogging());
```

:::note
Timed middleware is part of the Shiny.Mediator.Maui package and is installed by default with the `UseMaui` setup.
Performance logging middleware is installed by the default mediator setup
:::

To use it on with your request handlers, simply mark them with the `TimedLoggingAttribute`:
## Configuration

```csharp
public class MyRequestHandler : IRequestHandler<MyRequest>
```json
{
[TimedLogging(3000)] // If longer than 3000 milliseconds, log as an error
public async Task Execute(MyRequest request, CancellationToken ct)
{
// do your work
"Mediator": {
"PerformanceLogging": {
"My.Contracts.*": {
"*": {
"ErrorThresholdMilliseconds": 1000
}
}
}
}
}
}
```
4 changes: 4 additions & 0 deletions src/content/docs/server/ef.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Entity Framework
---
# TODO
5 changes: 5 additions & 0 deletions src/content/docs/server/webhosting.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Web Hosting Extensions
---

# TODO

0 comments on commit 7046e47

Please sign in to comment.