Use injected repository service instead of static singleton
See original GitHub issueIs your feature request related to a problem? Please describe.
I observed this problem when added quartz to my ASP.NET project and integration tests started to fail because of the error “Scheduler with the name xxx already exists”. After investigations, I found out that this is because of a shared context between different instances of WebApplicationFactory
. Reading the source codes led me to this line which shows a static repository is being used as a singleton. As the tests run in shared memory space, this static object is also shared between them.
Although the error could be solved by defining locks in custom hosted services, this behavior is breaking the isolation of tests and requires additional considerations in any case. For example, we cannot use separate databases for each test if they are going to run in parallel.
Describe the solution you’d like Register the repository as a singleton service and inject it into the dependent classes.
Also relates to #399.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
I think this requires some breaking changes in order to work. Unless you can figure out a way to support in 3.x without breaking API and compatibility? Scheduling for v4 for now.
@kolpav it’s in v3 branch and available on MyGet already, but not in v4 (main).