File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,31 @@ public class StopwatchMiddleware
150150And you want to apply it to a single HTTP endpoint without having to dirty your hands with an attribute. You can use that naming
151151convention up above like so:
152152
153- sample: sample_applying_middleware_programmatically_to_one_chain
153+ <!-- snippet: sample_applying_middleware_programmatically_to_one_chain -->
154+ <a id =' snippet-sample_applying_middleware_programmatically_to_one_chain ' ></a >
155+ ``` cs
156+ public class MeasuredEndpoint
157+ {
158+ // The signature is meaningful here
159+ public static void Configure (HttpChain chain )
160+ {
161+ // Call this method before the normal endpoint
162+ chain .Middleware .Add (MethodCall .For <StopwatchMiddleware >(x => x .Before ()));
163+
164+ // Call this method after the normal endpoint
165+ chain .Postprocessors .Add (MethodCall .For <StopwatchMiddleware >(x => x .Finally (null , null )));
166+ }
167+
168+ [WolverineGet (" /timed" )]
169+ public async Task <string > Get ()
170+ {
171+ await Task .Delay (100 .Milliseconds ());
172+ return " how long did I take?" ;
173+ }
174+ }
175+ ```
176+ <sup ><a href =' https://github.com/JasperFx/wolverine/blob/main/src/Http/WolverineWebApi/MiddlewareEndpoints.cs#L30-L52 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-sample_applying_middleware_programmatically_to_one_chain ' title =' Start of snippet ' >anchor</a ></sup >
177+ <!-- endSnippet -->
154178
155179
156180## Apply Middleware by Policy
You can’t perform that action at this time.
0 commit comments