Skip to content

Commit 0adafd7

Browse files
committed
Update docs
1 parent 3544419 commit 0adafd7

File tree

7 files changed

+132
-98
lines changed

7 files changed

+132
-98
lines changed

docs/documentation/advanced-topics.md

Whitespace-only changes.

docs/documentation/consumers.md

Whitespace-only changes.

docs/documentation/error-handling.md

Whitespace-only changes.

docs/documentation/eventbusbuilder.md

Whitespace-only changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Getting Started with Reflection Eventing
2+
3+
Welcome to the "Getting Started" guide for the Reflection Eventing library. This guide will walk you through the initial setup and basic usage of the library.
4+
5+
## Prerequisites
6+
7+
Before you begin, ensure you have the following:
8+
9+
- .NET 5.0 or later installed on your machine.
10+
- A basic understanding of dependency injection and asynchronous programming in .NET.
11+
12+
## Installation
13+
14+
To install the Reflection Eventing library, add the following NuGet package to your project:
15+
16+
```bash
17+
dotnet add package ReflectionEventing
18+
```
19+
20+
## Basic Setup
21+
22+
#### Step 1: Define Your Events and Consumers
23+
24+
First, define the events and consumers that will handle those events. An event is typically a simple class or record, and a consumer is a class that implements the IConsumer<TEvent> interface.
25+
26+
```csharp
27+
public record TestEvent;
28+
29+
public class TestConsumer : IConsumer<TestEvent>
30+
{
31+
public Task ConsumeAsync(TestEvent payload, CancellationToken cancellationToken)
32+
{
33+
// Handle the event
34+
return Task.CompletedTask;
35+
}
36+
}
37+
```
38+
39+
#### Step 2: Configure the Event Bus
40+
41+
Next, configure the event bus in your application's dependency injection container. You can do this in the ConfigureServices method of your Startup class or in the Host.CreateDefaultBuilder method.
42+
43+
```csharp
44+
using Microsoft.Extensions.DependencyInjection;
45+
using Microsoft.Extensions.Hosting;
46+
using ReflectionEventing;
47+
48+
public class Program
49+
{
50+
public static void Main(string[] args)
51+
{
52+
CreateHostBuilder(args).Build().Run();
53+
}
54+
55+
public static IHostBuilder CreateHostBuilder(string[] args) =>
56+
Host.CreateDefaultBuilder(args)
57+
.ConfigureServices((context, services) =>
58+
{
59+
services.AddEventBus(builder =>
60+
{
61+
builder.Options.UseEventPolymorphism = true;
62+
builder.AddConsumer<TestConsumer>();
63+
});
64+
});
65+
}
66+
```
67+
68+
#### Step 3: Publish Events
69+
70+
To publish events, resolve the IEventBus service from the dependency injection container and call the PublishAsync method.
71+
72+
```csharp
73+
using Microsoft.Extensions.DependencyInjection;
74+
using Microsoft.Extensions.Hosting;
75+
using ReflectionEventing;
76+
77+
public class EventPublisher
78+
{
79+
private readonly IEventBus _eventBus;
80+
81+
public EventPublisher(IEventBus eventBus)
82+
{
83+
_eventBus = eventBus;
84+
}
85+
86+
public async Task PublishTestEventAsync()
87+
{
88+
await _eventBus.PublishAsync(new TestEvent());
89+
}
90+
}
91+
```
92+
93+
#### Step 4: Run Your Application
94+
95+
Run your application and ensure that the events are being published and consumed as expected.

docs/documentation/index.md

Lines changed: 33 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,56 @@
1-
# Reflection Eventing Docs
1+
# Reflection Eventing Documentation
22

3-
[Created with ❤ in Poland by lepo.co](https://dev.lepo.co/)
4-
ReflectionEventing is a powerful tool for developers looking to create decoupled designs in WPF, WinForms, or CLI applications. By leveraging the power of Dependency Injection (DI) and eventing, ReflectionEventing promotes better Inversion of Control (IoC), reducing coupling and enhancing the modularity and flexibility of your applications.
3+
Welcome to the documentation for the Reflection Eventing project. This documentation provides detailed information on how to configure and use the various components of the Reflection Eventing library.
54

6-
[![GitHub license](https://img.shields.io/github/license/lepoco/reflectioneventing)](https://github.com/lepoco/reflectioneventing/blob/master/LICENSE) [![Nuget](https://img.shields.io/nuget/v/ReflectionEventing)](https://www.nuget.org/packages/ReflectionEventing/) [![Nuget](https://img.shields.io/nuget/dt/ReflectionEventing?label=nuget)](https://www.nuget.org/packages/ReflectionEventing/) [![Sponsors](https://img.shields.io/github/sponsors/lepoco)](https://github.com/sponsors/lepoco)
5+
## Table of Contents
76

8-
## 👀 What does this repo contain?
7+
1. [Getting Started](/documentation/getting-started.html)
8+
2. [Configuration](/documentation/configuration.html)
9+
3. [EventBusBuilder](/documentation/eventbusbuilder.html)
10+
4. [Consumers](/documentation/consumers.html)
11+
5. [Error Handling](/documentation/error-handling.html)
12+
6. [Advanced Topics](/documentation/advanced-topics.html)
13+
7. [API Reference](/api/ReflectionEventing.html)
914

10-
This repository houses the source code for the ReflectionEventing NuGet package. The package utilizes C# reflection to register services that can listen for and respond to local events.
15+
## Overview
1116

12-
## 🛟 Support plans
17+
The Reflection Eventing library provides a flexible and powerful way to handle events in your application. It allows you to define event consumers, configure event buses, and manage event processing with ease.
1318

14-
To ensure you receive the expert guidance you need, we offer a variety of support plans designed to meet the diverse needs of our community. Whether you are looking to in memory eventing or need assistance with our other libraries, our tailored support solutions are here to help. From priority email support to 24/7 dedicated assistance, we provide flexible plans to suit your project requirements.
19+
### Key Features
1520

16-
[Take a look at the lepo.co support plans](https://lepo.co/support)
21+
- **EventBusBuilder**: A class to configure and build an event bus with a specific set of consumers.
22+
- **Consumers**: Define consumers that handle specific event types.
23+
- **Configuration Options**: Various options to control the behavior of the event bus, including event polymorphism, background queues, and error handling.
24+
- **Error Handling**: Mechanisms to handle events that fail processing, including the use of error queues.
1725

18-
## 🤝 Help us keep working on this project
26+
## Getting Started
1927

20-
Support the development of Reflection Eventing and other innovative projects by becoming a sponsor on GitHub! Your monthly or one-time contributions help us continue to deliver high-quality, open-source solutions that empower developers worldwide.
28+
To get started with Reflection Eventing, refer to the [Getting Started](/documentation/getting-started.html) guide. This guide will walk you through the initial setup and basic usage of the library.
2129

22-
[Sponsor Reflection Eventing on GitHub](https://github.com/sponsors/lepoco)
30+
## Configuration
2331

24-
## Gettings started
32+
Learn how to configure the event bus and its components in the [Configuration](/documentation/configuration.html) section. This includes details on the `EventBusBuilder` and its options.
2533

26-
ReflectionEventing is available as NuGet package on NuGet.org:
27-
<https://www.nuget.org/packages/ReflectionEventing>
28-
<https://www.nuget.org/packages/ReflectionEventing.Autofac>
29-
<https://www.nuget.org/packages/ReflectionEventing.Castle.Windsor>
30-
<https://www.nuget.org/packages/ReflectionEventing.DependencyInjection>
31-
<https://www.nuget.org/packages/ReflectionEventing.Ninject>
32-
<https://www.nuget.org/packages/ReflectionEventing.Unity>
34+
## EventBusBuilder
3335

34-
You can add it to your project using .NET CLI:
36+
The [EventBusBuilder](/documentation/eventbusbuilder.html) section provides an in-depth look at how to use the `EventBusBuilder` class to configure and build your event bus.
3537

36-
```powershell
37-
dotnet add package ReflectionEventing.DependencyInjection
38-
```
38+
## Consumers
3939

40-
, or package manager console:
40+
The [Consumers](/documentation/consumers.html) section explains how to define and register consumers that handle specific event types.
4141

42-
```powershell
43-
NuGet\Install-Package ReflectionEventing.DependencyInjection
44-
```
42+
## Error Handling
4543

46-
### 🛠️ How to Use ReflectionEventing
44+
Understand how to handle errors in event processing in the [Error Handling](/documentation/error-handling.html) section. This includes using error queues and handling consumer exceptions.
4745

48-
#### 1. Register Consumers and the Event Bus
46+
## Advanced Topics
4947

50-
In this step, we register our ViewModel as a singleton and add it as a consumer to the event bus. This allows the ViewModel to listen for events published on the bus.
48+
Explore advanced topics and best practices in the [Advanced Topics](/documentation/advanced-topics.html) section.
5149

52-
```csharp
53-
IHost host = Host.CreateDefaultBuilder()
54-
.ConfigureServices((context, services) =>
55-
{
56-
services.AddSingleton<MainWindowViewModel>();
57-
services.AddEventBus(e =>
58-
{
59-
e.AddConsumer<MainWindowViewModel>();
60-
});
61-
}
62-
)
63-
.Build();
64-
```
50+
## API Reference
6551

66-
#### 2. Publish Events
52+
For detailed API documentation, refer to the [API Reference](/api/ReflectionEventing.html).
6753

68-
Here, we create a background service that publishes an event on the event bus. This event could be anything - in this case, we're publishing a `BackgroundTicked` event.
54+
---
6955

70-
```csharp
71-
public class MyBackgroundService(IEventBus eventBus)
72-
{
73-
public void PublishEvent()
74-
{
75-
eventBus.Publish(new BackgroundTicked());
76-
}
77-
}
78-
```
79-
80-
#### 3. Listen for Events
81-
82-
Finally, we implement the `IConsumer<T>` interface in our ViewModel. This allows the ViewModel to consume `BackgroundTicked` events. When a `BackgroundTicked` event is published, the `ConsumeAsync` method is called, and we update the `CurrentTick` property.
83-
84-
```csharp
85-
public partial class MainWindowViewModel : ObservableObject, IConsumer<BackgroundTicked>
86-
{
87-
[ObservableProperty]
88-
private int _currentTick = 0;
89-
90-
public Task ConsumeAsync(BackgroundTicked payload, CancellationToken cancellationToken)
91-
{
92-
CurrentTick = payload.Value;
93-
94-
return Task.CompletedTask;
95-
}
96-
}
97-
```
98-
99-
## Special thanks
100-
101-
JetBrains was kind enough to lend a license for the open-source **dotUltimate** for _ReflectionEventing_ development.
102-
Learn more here:
103-
104-
- <https://www.jetbrains.com/dotnet/>
105-
- <https://www.jetbrains.com/opensource/>
106-
107-
## Compilation
108-
109-
To build the project, use Visual Studio 2022 and open the .sln file.
110-
111-
Visual Studio
112-
**ReflectionEventing** is an Open Source project. You are entitled to download and use the freely available Visual Studio Community Edition to build, run or develop for ReflectionEventing. As per the Visual Studio Community Edition license, this applies regardless of whether you are an individual or a corporate user.
113-
114-
## Code of Conduct
115-
116-
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
117-
118-
## License
119-
120-
**ReflectionEventing** is free and open source software licensed under **MIT License**. You can use it in private and commercial projects.
121-
Keep in mind that you must include a copy of the license in your project.
56+
For more information and examples, please refer to the individual sections listed above.

docs/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ items:
44
- name: Documentation
55
href: /documentation
66
items:
7+
- name: Getting started
8+
href: documentation/getting-started.md
79
- name: Configuration
810
href: documentation/configuration.md
11+
- name: Consumers
12+
href: documentation/consumers.md
913
- name: API
1014
href: api/

0 commit comments

Comments
 (0)