question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use injected repository service instead of static singleton

See original GitHub issue

Is 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:open
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
lahmacommented, Dec 4, 2021

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.

1reaction
lahmacommented, Aug 11, 2022

@kolpav it’s in v3 branch and available on MyGet already, but not in v4 (main).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Singleton class rather than Injecting repository ...
Vaadin views only allows injecting @Autowired repositories in constructor, but instead of doing that I implemented it using a Singleton ...
Read more >
Why You Should Prefer Singleton Pattern over a Static ...
Use Dependency Injection with singleton lifetime as a best practice wherever possible. Use singleton pattern rather than static classes. Using a ...
Read more >
How not to do dependency injection - the static or singleton ...
People often seem to completely forget that we are trying to inject dependencies and instead, use the container to retrieve them. Instead of...
Read more >
Is it a bad practice to use Singleton for DI in Asp.net rather ...
Is it a bad practice to use X whenever possible? Yes. It is bad practice to turn off your brain and lean on...
Read more >
Singleton vs. static classes in C# | InfoWorld
Understand the differences between a singleton class and a static class and when to use which in your applications.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found