Skip to content

Locking in middleware #51

Answered by augustoproiete
gitzko asked this question in Q&A
Mar 20, 2023 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Hey @gitzko,Lock (or LockAsync) is not needed in a constructor of an ASP .NET Core middleware because the middleware is constructed only once per application lifetime, so there's no multiple threads writing to the GlobalLogContext.

As for your second question, It's hard to answer without knowing more details of your app, but fundamentally I'd recommend that you set the property at the closest place where you have the value for it... If the middleware constructor is where you first have the value you want to set globally, then that seems like the right place for it.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@gitzko
Comment options

@augustoproiete
Comment options

@gitzko
Comment options

@gitzko
Comment options

Answer selected by gitzko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants