Skip to content

Commit fa6cb2f

Browse files
committed
Add readme
1 parent 0e72695 commit fa6cb2f

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,51 @@ Current options:
264264
| DontDestroyOnLoad | Calls GameObject.DontDestroyOnLoad(SceneInjector) during initialization. This prevents the game object from being destroyed | True |
265265

266266
## Notes
267-
- To see sample usage check out tests and test scenes
267+
- To see sample usage check out tests and test scenes
268+
269+
# Injecter.FastMediatR
270+
271+
An IMediatR proxy which helps you use MediatR in performance critical scenarios.
272+
273+
Using the IFastMediator interface results in:
274+
275+
- No pipeline behaviors are called.
276+
- The call is not asynchronous.
277+
- When repeating a request with an IFastMediator instance the request handlers get cached.
278+
279+
## Usage
280+
```c#
281+
// Create a regular request
282+
public sealed class Add : IRequest<int>
283+
{
284+
public int A { get; set; }
285+
286+
public int B { get; set; }
287+
}
288+
289+
// Implement ISyncHandler
290+
public sealed class AddHandler : ISyncHandler<Add, int>
291+
{
292+
public Task<int> Handle(Add request, CancellationToken cancellationToken) => Task.FromResult(HandleSync(request));
293+
294+
public int HandleSync(Add request) => request.A + request.B;
295+
}
296+
297+
// Add MediatR and FastMediatR
298+
IServiceProvider serviceProvider = new ServiceCollection()
299+
.AddFastMediatR()
300+
.AddMediatR() //Add assemblies
301+
.BuildServiceProvider()
302+
303+
// Use it
304+
IFastMediator fastMediator = serviceProvider.GetRequiredService<IFastMediator>();
305+
Add request = new Add { A = 1, B = 1 };
306+
307+
int result = fastMediator.SendSync(request);
308+
309+
Assert.Equal(2, result);
310+
311+
fastMediator.Dispose();
312+
```
313+
314+
When sending your requests through IMediator everything works the usual way, because ISyncHandler inherits from IRequestHandler.

0 commit comments

Comments
 (0)