All Questions
Tagged with singleton dependency-injection
12 questions
-1
votes
3
answers
785
views
Would Injecting dependencies in C# as default parameters be a bad practice?
Given the (old) debate over whether Singletons are overused/abused/are worth it - would it be a bad idea to inject the dependencies as default parameters? In this way, we could get rid of defining ...
-2
votes
3
answers
827
views
Singleton as Interface for testability via dependancy injection
It can be found in many advices on topic that having Singletons is an anti-pattern. Especially for cases of testability. Can someone please advice/critique on this way (please see code below) of ...
0
votes
1
answer
115
views
How should I provide access to "global" objects down to other objects which are contained in a central "application" object
Note This is a bit lengthy to have give a better understanding of the situation and to get some context. You might spot other architectural flaws (it's from an ancient application). I appreciate any ...
2
votes
0
answers
319
views
Dependency injection in .NET Core 3.x Worker Services: Why so hard to consume Transient services now?
I have a Repository service that should be Transient. It is used in many applications.
I have a new application that's a Console App, and current guidance suggests implementing my business logic in ...
7
votes
1
answer
19k
views
Singleton with dependency injection ,is that a good practice in some cases?
It's a good idea to have a Singleton implementation with dependency injection?
I have some classes that performs some heavy tasks on instantiation (related to database loading).
I would like to use ...
9
votes
3
answers
15k
views
React Native - Is using a singleton the best alternative to DI?
I've been reading a lot about the singleton pattern and how it's "bad" because it makes the classes using it hard to test so it should be avoided. I've read some articles explaining how the singleton ...
44
votes
11
answers
6k
views
Are so called "cross-cutting concerns" a valid excuse to break SOLID/DI/IoC?
My colleagues like to say "logging/caching/etc. is a cross-cutting concern" and then proceed using the corresponding singleton everywhere. Yet they love IoC and DI.
Is it really a valid excuse to ...
8
votes
2
answers
3k
views
How to avoid a crazy amount of interfaces in UI with dependency injection?
Problem
I recently read a lot about Singletons being bad and how dependency injection (which I understand as "using interfaces") is better. When I implemented part of this with callbacks/interfaces/DI ...
0
votes
3
answers
565
views
How should I refactor a singleton (to be used by a container) when the refactored class requires initialization and takes a dependency?
I'm refactoring an old app to use dependency injection.n I'm pretty new to DI.
I have a class that used to be a singleton. I'm refactoring it into a non-singleton class and using the container to ...
4
votes
2
answers
11k
views
Factory for creating a singleton instance
We have some legacy code that has a bunch of singletons all over the place (written in C#).
The singleton is a fairly "classic" implementation of the pattern:
public class SomeSingleton
{
...
1
vote
3
answers
3k
views
Why does dependency injection encourage collaboration to be exposed via constructors?
The general approach to DI that I see in answers like
So Singletons are bad, then what? encourages
business objects that collaborate with other objects to (a) not
directly create those instances and (...
620
votes
13
answers
273k
views
So Singletons are bad, then what?
There has been a lot of discussion lately about the problems with using (and overusing) Singletons. I've been one of those people earlier in my career too. I can see what the problem is now, and yet, ...