Skip to content

Commit e40c0ca

Browse files
authored
Merge pull request #77 from mayuanyang/better-readme
add wiki
2 parents 5582c39 + 6181c90 commit e40c0ca

14 files changed

+403
-0
lines changed

wiki/advanced-features.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Advanced Features
2+
3+
Mediator.Net offers several advanced features to enhance its functionality.
4+
5+
## Context Services
6+
7+
Share services between middleware and handlers:
8+
9+
```csharp
10+
// In middleware
11+
public Task Execute(TContext context, CancellationToken cancellationToken)
12+
{
13+
context.RegisterService(new AuditInfo { Timestamp = DateTime.UtcNow });
14+
return Task.CompletedTask;
15+
}
16+
17+
// In handler
18+
public async Task Handle(IReceiveContext<MyCommand> context, CancellationToken cancellationToken)
19+
{
20+
if (context.TryGetService(out AuditInfo auditInfo))
21+
{
22+
// Use the audit info
23+
}
24+
}
25+
```
26+
27+
## Publishing Events from Handlers
28+
29+
```csharp
30+
public async Task Handle(IReceiveContext<CreateOrderCommand> context, CancellationToken cancellationToken)
31+
{
32+
// Process the command
33+
var order = new Order(context.Message.CustomerId);
34+
35+
// Publish domain event
36+
await context.Publish(new OrderCreatedEvent
37+
{
38+
OrderId = order.Id,
39+
CustomerId = order.CustomerId
40+
});
41+
}

wiki/contributing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing
2+
3+
We welcome contributions! Please see our [Contributing Guide](../CONTRIBUTING.md) for details.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dependency Injection Integration
2+
3+
Mediator.Net integrates with various dependency injection containers to manage the lifecycle of handlers and other components.
4+
5+
## Microsoft.Extensions.DependencyInjection
6+
7+
```bash
8+
Install-Package Mediator.Net.MicrosoftDependencyInjection
9+
```
10+
11+
```csharp
12+
services.AddMediator(builder =>
13+
{
14+
builder.RegisterHandlers(typeof(Program).Assembly);
15+
});
16+
```
17+
18+
## Autofac
19+
20+
```bash
21+
Install-Package Mediator.Net.Autofac
22+
```
23+
24+
```csharp
25+
var builder = new ContainerBuilder();
26+
var mediatorBuilder = new MediatorBuilder()
27+
.RegisterHandlers(typeof(Program).Assembly);
28+
29+
builder.RegisterMediator(mediatorBuilder);
30+
var container = builder.Build();
31+
```
32+
33+
## Other Supported Containers
34+
35+
- **SimpleInjector**: `Mediator.Net.SimpleInjector`
36+
- **StructureMap**: `Mediator.Net.StructureMap`
37+
- **Ninject**: `Mediator.Net.Ninject`

wiki/documentation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Documentation
2+
3+
For more detailed documentation, examples, and advanced scenarios, visit our [Wiki](https://github.com/mayuanyang/Mediator.Net/wiki).
4+
5+
For additional resources and support, please refer to the following:
6+
7+
- [Contributing Guide](../CONTRIBUTING.md)
8+
- [License](../LICENSE.txt)
9+
- [Support](../README.md#️-support)

wiki/features.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Features
2+
3+
Mediator.Net offers the following features:
4+
5+
- **Command/Query Separation**: Clear separation between commands, queries, and events.
6+
- **Pipeline Support**: Extensible middleware pipeline for cross-cutting concerns.
7+
- **Streaming Support**: Handle multiple responses with `IAsyncEnumerable`.
8+
- **Dependency Injection**: Built-in support for popular IoC containers.
9+
- **Event Publishing**: Publish events from within handlers.
10+
- **Flexible Registration**: Both explicit and assembly scanning registration.
11+
- **Middleware Ecosystem**: Rich collection of pre-built middlewares.

wiki/handler-registration.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Handler Registration
2+
3+
Mediator.Net supports two methods for registering handlers: assembly scanning and explicit registration.
4+
5+
## Assembly Scanning (Recommended)
6+
7+
```csharp
8+
var mediator = new MediatorBuilder()
9+
.RegisterHandlers(typeof(Program).Assembly)
10+
.Build();
11+
```
12+
13+
## Explicit Registration
14+
15+
```csharp
16+
var mediator = new MediatorBuilder()
17+
.RegisterHandlers(() => new List<MessageBinding>
18+
{
19+
new MessageBinding(typeof(CreateUserCommand), typeof(CreateUserCommandHandler)),
20+
new MessageBinding(typeof(GetUserQuery), typeof(GetUserQueryHandler)),
21+
new MessageBinding(typeof(UserCreatedEvent), typeof(UserCreatedEventHandler))
22+
})
23+
.Build();

wiki/index.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Mediator.Net Wiki
2+
3+
This is the wiki for the Mediator.Net project. Below are the sections that provide detailed information about the project.
4+
5+
- [Features](features.md)
6+
- [Installation](installation.md)
7+
- [Quick Start](quick-start.md)
8+
- [Usage Examples](usage-examples.md)
9+
- [Handler Registration](handler-registration.md)
10+
- [Pipeline & Middleware](pipeline-middleware.md)
11+
- [Dependency Injection Integration](dependency-injection-integration.md)
12+
- [Official Middleware Packages](official-middleware-packages.md)
13+
- [Advanced Features](advanced-features.md)
14+
- [Documentation](documentation.md)
15+
- [Contributing](contributing.md)
16+
- [License](license.md)
17+
- [Support](support.md)

wiki/installation.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Installation
2+
3+
To install Mediator.Net, you can use NuGet or the .NET CLI.
4+
5+
## Using NuGet
6+
7+
```bash
8+
Install-Package Mediator.Net
9+
```
10+
11+
## Using .NET CLI
12+
13+
```bash
14+
dotnet add package Mediator.Net

wiki/license.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License
2+
3+
This project is licensed under the MIT License - see the [LICENSE.txt](../LICENSE.txt) file for details.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Official Middleware Packages
2+
3+
Mediator.Net provides several official middleware packages to extend its functionality.
4+
5+
## Serilog Logging
6+
7+
```bash
8+
Install-Package Mediator.Net.Middlewares.Serilog
9+
```
10+
11+
```csharp
12+
.ConfigureGlobalReceivePipe(x => x.UseSerilog(LogEventLevel.Information))
13+
```
14+
15+
## Unit of Work
16+
17+
```bash
18+
Install-Package Mediator.Net.Middlewares.UnitOfWork
19+
```
20+
21+
Provides `CommittableTransaction` support for transactional operations.
22+
23+
## EventStore Integration
24+
25+
```bash
26+
Install-Package Mediator.Net.Middlewares.EventStore
27+
```
28+
29+
Automatically persists events to EventStore.

0 commit comments

Comments
 (0)