@@ -27,22 +27,17 @@ Distributed tracing and trace context is built in .NET, You can get more insight
27
27
### Startup class
28
28
29
29
``` 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 ();
36
32
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 ();
42
34
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 ();
46
41
```
47
42
48
43
### Accessing correlation ID
@@ -78,34 +73,28 @@ In order to pass correlation ID to subsequent requests, additional HTTP message
78
73
Add ` CorrelatorHttpMessageHandler ` to HTTP client's message handler pipeline like this:
79
74
80
75
``` 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
+ // ...
109
98
```
110
99
111
100
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
118
107
Correlator is shipped with lightweight validator, ` CorrelationValueLengthValidator ` , which decides whether received
119
108
value is valid simply based on its length.
120
109
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 ));
128
114
```
129
115
130
116
## Documentation
0 commit comments