.Net 1 Flashcards

1
Q

How to combine two cancellation tokens in one?

A

You can use
public static CancellationTokenSource CreateLinkedTokenSource(
CancellationToken token1,
CancellationToken token2)

method and get a token from the CancellationTokenSource.

Example:
var combinedCancelationToken = CancellationTokenSource.CreateLinkedTokenSource(
startupCancellationToken, applicationLifetime.ApplicationStarted).Token;

combinedCancelationToken will be canceled if one of the source tokens was canceled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How you can wait until the hosted application is started?

A

You can use IApplicationLifetime.ApplicationStarted property. The return type of the property is CancellationToken. So when it’s canceled it means the application is started.

Example:
await Task.Delay(Timeout.InfiniteTimeSpan, applicationLifetime.ApplicationStarted)
.ContinueWith(_ => { }, TaskContinuationOptions.OnlyOnCanceled) // to avoid OperationCanceledException.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between UseRouting and UseEndpoints?

A

UseRouting: Matches request to an endpoint.

UseEndpoints: Execute the matched endpoint.

It decouples the route matching and resolution functionality from the endpoint executing functionality. This makes the ASP.NET Core framework more flexible and allows other middlewares to act between UseRouting and UseEndpoints

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where in pipeline do you have to call UseAuthentication?

A

Between UseRouting and UseEndpoints.

So that route information is available for authentication decisions and before UseEndpoints so that users are authenticated before accessing the endpoints.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Do you need to explicetely call UseRouting.

A

Yes, for .net core.
But in.net 6 you don’t, you can do it explicetely to move routing matching to another step in pipeline, by default it’s the first one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly