danielpalme / IocPerformance

Performance comparison of .NET IoC containers
https://danielpalme.github.io/IocPerformance
Apache License 2.0
874 stars 157 forks source link

asp.net benchmark - multiple scopes per controller #118

Closed jzabroski closed 2 years ago

jzabroski commented 5 years ago

A common architecture on projects I work on is to allow multiple scopes per controller, where the controller is an entry point for parallel processing some work. For example, creating multiple DbContext objects, one per parallel unit of work. Since DbContext is not thread-safe, a Func<DbContext> is required with a way to OpenScope on the existing scope, creating a new scope that is either a child/nested scope or orthogonal scope to existing scopes.

Issues I have come across implementing this pattern include threading security context (authentication and authorization) to the parallel unit of work, as the child threads do not inherit the identity context, so the identity has to be thunked to the child threads.