Open carlosrfernandez opened 2 years ago
@carlosrfernandez, @jonclare - Just thinking about this. Probably stating the obvious here, but in general, a given DbContext instance is not designed to be used concurrently by multiple threads. With the changes made in #63, we can now specify projections which use different DbContext instances if needed, using the new ServiceProjectionContext
.
With the changes made in #31, it's worth considering if we should make this optional - i.e. to run projections concurrently or not. If you get your DbContext from a DI scope, it will be the same instance across all projections which use that resource - so it's a consideration for the consumer to make sure they're not using the DbContext in a non-thread-safe way under that scenario.
Just thinking about it further though - I'm not even sure it really makes sense for projections to use a scoped DbContext instance. Let's discuss at some point!
Having multiple projections on the same DbContext currently doesn't work correctly.
An exception is thrown when a single event is handled by two or more projections for the same DbContext.
Look here