Skip to content

Commit 1bbbe2d

Browse files
authored
Update documentation (#65)
* Update docs/readme
1 parent 2a26019 commit 1bbbe2d

File tree

5 files changed

+59
-79
lines changed

5 files changed

+59
-79
lines changed

README.md

+35-49
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,17 @@ Distributed tracing and trace context is built in .NET, You can get more insight
2727
### Startup class
2828

2929
```csharp
30-
public class MyLittleStartup
31-
{
32-
public void ConfigureServices(IServiceCollection services)
33-
{
34-
services.AddDefaultCorrelator();
35-
}
30+
var builder = WebApplication.CreateBuilder(args);
31+
builder.Services.AddDefaultCorrelator();
3632

37-
public void Configure(IApplicationBuilder app)
38-
{
39-
// register as first middleware
40-
// (or as soon as possible to benefit from having correlation ID)
41-
app.UseCorrelator();
33+
var app = builder.Build();
4234

43-
app.UseMvc();
44-
}
45-
}
35+
// register as first middleware
36+
// (or as soon as possible to benefit from having correlation ID)
37+
app.UseCorrelator();
38+
39+
// ...
40+
app.Run();
4641
```
4742

4843
### Accessing correlation ID
@@ -78,34 +73,28 @@ In order to pass correlation ID to subsequent requests, additional HTTP message
7873
Add `CorrelatorHttpMessageHandler` to HTTP client's message handler pipeline like this:
7974

8075
```csharp
81-
public class MyLittleStartup
82-
{
83-
public void ConfigureServices(IServiceCollection services)
84-
{
85-
// named HTTP client
86-
services
87-
.AddHttpClient("DummyClient")
88-
.WithCorrelation();
89-
90-
// typed HTTP client
91-
services
92-
.AddHttpClient<FooClient>()
93-
.WithCorrelation();
94-
95-
// registering HTTP message handler manually
96-
services
97-
.AddHttpClient("FizzClient")
98-
.AddHttpMessageHandler<CorrelatorHttpMessageHandler>();
99-
100-
// registering HTTP client with custom settings
101-
// (global options - CorrelatorOptions.Forward - won't be used)
102-
services
103-
.AddHttpClient<LegacyClient>()
104-
.WithCorrelation(PropagationSettings.PropagateAs("X-Legacy-Correlation-Id"));
105-
}
106-
107-
// ...
108-
}
76+
// named HTTP client
77+
builder.Services
78+
.AddHttpClient("DummyClient")
79+
.WithCorrelation();
80+
81+
// typed HTTP client
82+
builder.Services
83+
.AddHttpClient<FooClient>()
84+
.WithCorrelation();
85+
86+
// registering HTTP message handler manually
87+
builder.Services
88+
.AddHttpClient("FizzClient")
89+
.AddHttpMessageHandler<CorrelatorHttpMessageHandler>();
90+
91+
// registering HTTP client with custom settings
92+
// (global options - CorrelatorOptions.Forward - won't be used)
93+
builder.Services
94+
.AddHttpClient<LegacyClient>()
95+
.WithCorrelation(PropagationSettings.PropagateAs("X-Legacy-Correlation-Id"));
96+
97+
// ...
10998
```
11099

111100
See "[Configure the HttpMessageHandler](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-2.1#configure-the-httpmessagehandler)" for more details about usage of HTTP message handler.
@@ -118,13 +107,10 @@ turned off. In order to turn validation on, implementation of `ICorrelationValid
118107
Correlator is shipped with lightweight validator, `CorrelationValueLengthValidator`, which decides whether received
119108
value is valid simply based on its length.
120109

121-
```
122-
public void ConfigureServices(IServiceCollection services)
123-
{
124-
services
125-
.AddDefaultCorrelator()
126-
.WithValidator(new CorrelationValueLengthValidator(64));
127-
}
110+
```csharp
111+
builder.Services
112+
.AddDefaultCorrelator()
113+
.WithValidator(new CorrelationValueLengthValidator(64));
128114
```
129115

130116
## Documentation

docs/configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ By _default_, Correlator is configured following way:
1717
To adjust setting, use `AddDefaultCorrelator` or `AddCorrelator` overload:
1818

1919
```csharp
20-
services.AddDefaultCorrelator(
20+
builder.Services.AddDefaultCorrelator(
2121
correlatorOptions =>
2222
{
2323
// disable correlation ID factory

docs/registration.md

+21-27
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,43 @@ Apart of registering default implementations of `ICorrelationContextFactory` and
44
also provide own implementation.
55

66
```csharp
7-
public class MyLittleStartup
8-
{
9-
public void ConfigureServices(IServiceCollection services)
10-
{
11-
services
12-
.AddCorrelator()
13-
.WithCorrelationContextFactory<MyLittleCorrelationContextFactory>()
14-
.WithCorrelationEmitter<MyLittleCorrelationEmitter>();
15-
}
16-
17-
// ...
18-
}
7+
var builder = WebApplication.CreateBuilder(args);
8+
9+
builder.Services
10+
.AddCorrelator()
11+
.WithCorrelationContextFactory<MyLittleCorrelationContextFactory>()
12+
.WithCorrelationEmitter<MyLittleCorrelationEmitter>();
1913
```
2014

2115
### Simple registration
2216

23-
```
24-
services.AddDefaultCorrelator();
17+
```csharp
18+
builder.Services.AddDefaultCorrelator();
2519

2620
// or
27-
services.AddDefaultCorrelator(options => { /* */ });
21+
builder.Services.AddDefaultCorrelator(options => { /* */ });
2822
```
2923

3024
### Custom registration
3125

32-
```
33-
ICorrelatorBuilder builder = services.AddCorrelator();
26+
```csharp
27+
ICorrelatorBuilder correlationBuilder = builder.Services.AddCorrelator();
3428

3529
// or
36-
ICorrelatorBuilder builder = services.AddCorrelator(options => { /* */ });
30+
ICorrelatorBuilder correlationBuilder = builder.Services.AddCorrelator(options => { /* */ });
3731
```
3832

3933
... and then either of:
40-
```
34+
```csharp
4135
// correlation context factory
42-
builder.WithDefaultCorrelationContextFactory(); // default implementation
43-
builder.WithCorrelationContextFactory<T>(); // type registration
44-
builder.WithCorrelationContextFactory(T factory); // instance registration
36+
correlationBuilder.WithDefaultCorrelationContextFactory(); // default implementation
37+
correlationBuilder.WithCorrelationContextFactory<T>(); // type registration
38+
correlationBuilder.WithCorrelationContextFactory(T factory); // instance registration
4539
4640
// correlation emitter
47-
builder.WithDefaultCorrelationEmitter(); // default implementation
48-
builder.WithCorrelationEmitter<T>(); // type registration
49-
builder.WithCorrelationEmitter(T emitter); // instance registration
41+
correlationBuilder.WithDefaultCorrelationEmitter(); // default implementation
42+
correlationBuilder.WithCorrelationEmitter<T>(); // type registration
43+
correlationBuilder.WithCorrelationEmitter(T emitter); // instance registration
5044
```
5145

5246
Both `ICorrelationContextFactory` and `ICorrelationEmitter` are registered as singletons.
@@ -58,8 +52,8 @@ end up with exception.
5852

5953
Optionally, you can register correlation validator like this (by default, no validator is registered):
6054

61-
```
62-
builder.WithValidator(new CorrelationValueLengthValidator(64));
55+
```csharp
56+
correlationBuilder.WithValidator(new CorrelationValueLengthValidator(64));
6357
```
6458

6559
`ICorrelationValidator` is registered as singleton.

run-bench-cmp.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dotnet build -c:Release && dotnet run -c:Release --project benchmarks/W4k.AspNetCore.Correlator.Benchmarks/ -- -f W4k.AspNetCore.Correlator.Benchmarks.Comparing* --join --allStats
1+
dotnet build -c:Release && dotnet run -c:Release -f net9.0 --project benchmarks/W4k.AspNetCore.Correlator.Benchmarks/ -- -f W4k.AspNetCore.Correlator.Benchmarks.Comparing* --join --allStats

run-bench.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dotnet build -c:Release && dotnet run -c:Release --project benchmarks/W4k.AspNetCore.Correlator.Benchmarks/ -- -f W4k.AspNetCore.Correlator.Benchmarks.Request* --join --allStats
1+
dotnet build -c:Release && dotnet run -c:Release -f net9.0 --project benchmarks/W4k.AspNetCore.Correlator.Benchmarks/ -- -f W4k.AspNetCore.Correlator.Benchmarks.Request* --join --allStats

0 commit comments

Comments
 (0)