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.
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. SinceDbContext
is not thread-safe, aFunc<DbContext>
is required with a way toOpenScope
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.