Questions tagged [dependency-injection]

Dependency Injection, is a design pattern where dependencies (instances of objects, properties) of a component are set through the constructor(s), methods or fields (properties). It is a special form of the more general dependency inversion.

Filter by
Sorted by
Tagged with
2
votes
4answers
476 views

Unnecessary (?) ReadOnly fields in Interfaces

Under the context of dependency injection - that is, an interface has mostly one implementation - I took the habit of exposing via the Interface a bunch of fields which are never called by the ...
2
votes
1answer
102 views

Is there a proper way to setup and use fake data in development for a DDD project using DI?

I have a project that has a DD design, and also uses dependency injection. During development, we connect to a test database which contains a former snapshot of production. This works well 95% of the ...
-3
votes
1answer
181 views

.Net Core Dependency Injection is an example of anti-pattern?

I want to use Dependecy injection in my new .net core project, but my manager thinks it is an anti-pattern usage. I already know benefits of dependency injection. But my manager cares architecture ...
-1
votes
1answer
179 views

Is it logical to use dependency injection in .net core library project? [closed]

Earlier, we serve with web service but we decide to use dll methods. Because served products are on same machine with common database. So we start to create a library with .net core. This library will ...
4
votes
2answers
314 views

Should dependency injection be used when there will only ever be one version of any class?

I'm writing a number of Selenium test classes that use Helper classes which contain processes that are often reused (ie. accessing a particular page, entering something into a specific field, etc.) ...
0
votes
1answer
43 views

If you use Spring dependency injection does the unit test require some Spring stuff?

I completely understand, I think, how injecting a dependency of a class allows that dependency to be mocked and the class to be tested with the mocked version. What I am not sure about is if you use @...
0
votes
0answers
68 views

How to design for optional dependency / optional functionality

Let's say for a Net Core library that I will deliver to the customer The library define a Interface like IGetData and also a default GetData class. The library also define a ICacher interface with a ...
1
vote
0answers
23 views

Dependency injection of UI components via React context

In React, it's common for libraries, and app-internal utilities, to used context-based dependency injection. Some examples: function MyComponent() { const client = useApolloClient(); // Apollo ...
2
votes
1answer
46 views

How to handle the Dependencies between Secondary Actor Adapters in the Hexagonal Architecture

I am applying the principles of Hexagonal Architecture (Ports and Adapters) and one aspect is slightly bothering me. In my opinion, the ports and adapters of the secondary actors should completely be ...
1
vote
2answers
154 views

Should a BDD feature be implemented by a one (and only one) clean architecture interactor?

TL; DR Given BDD documentation with features composed by several scenarios, should we: Create a single interactor per feature Create minor interactors per scenario, and composing the feature ...
0
votes
1answer
120 views

Is injecting user input dependency class to menu class appropriate?

I am currently designing classes for the User Interface (UI) of my application. When defining the interface of a class MenuTabSelector I faced a design decision of whether I should inject the user ...
1
vote
2answers
104 views

How to configure and setup an IOC Container for a library?

When using Dependency Injection across internal classes (implementation details) in a library which is to be consumed by multiple applications, is there a good way to configure the IOC container? ...
1
vote
2answers
114 views

How should a streamwriter be passed to an object considering OO and DI

I have an class named FileCreator which is used to write many strings to a stream. Basically, to achieve its job, the FileCreator needs two objects: a StreamWriter and the actual strings that will be ...
0
votes
0answers
36 views

Registering dependency implemented in separate assembly with shared interfaces

Situation: I have a project with a Business Layer (WizBang.BL) that contains nearly all of my application logic. It communicates with a Data Layer (WizBang.Data) that contains by entity classes and ...
1
vote
1answer
61 views

Abstracting common functionality for REST and CLI

I have made an application that deals with collections of images. Currently it has a REST api to add/remove images, create/clear/delete collections and a worker that can automatically fetch images ...
-1
votes
1answer
67 views

Dependency Injection and Factory resolution

In the below example, assume FooA and FooB each have constructors that have a large amount of dependencies being injected into them. If I have a class that needs to determine which IFoo ...
2
votes
3answers
187 views

Abstract Factory with Pure DI

I have an application where I'm using pure DI to construct my object graph. I would like to use a factory so I can create and destroy instances of a certain class at run time. The trouble is that ...
0
votes
2answers
225 views

Interface/Contracts in separate assembly?

Say I have BusinessService & domain logic as part of MyProj.MiddleTier csproj which connects to MyProj.DAL DataRepository via interface IDataRepository. I am using IOC unity container to build my ...
2
votes
2answers
220 views

3 layer architecture In DI based software

I'm building software with 3 layer architecture and asp.net core , as you know the Dependency Injection is Built Into Asp.net core As i know the 3 layer architecture diagram is like this: ...
2
votes
2answers
161 views

Documenting Dependency Injection Parameters

Should documentation be added for constructor parameters that are passed via dependency injection? In my current project I have decided to omit documentation to describe each of these parameters and ...
0
votes
1answer
172 views

IoC/DI + “normal” constructor arguments mvvm

I am using unity in C# to achieve dependency injection and inversion of control. What if I have a class, let's say a viewmodel, that depends on several services like a repository, a validator and a ...
1
vote
2answers
109 views

Chain of responsibility or simple dependency injection for Querying API

I am working on refactoring a project code that is wired up in a tangled way. It was started with decent dependency injection and over time with all custom requirements it looks it got tangled up. ...
1
vote
1answer
118 views

Proper way of handling large Dependency Injected constructors [duplicate]

I have many dataservices/classes injected into a constructor. public MyClassConstructor (IAclass A, IBclass B, .... , IZclass Z){ ... } The number I have to pass down goes well beyond 100. To ...
0
votes
1answer
74 views

Is it bad practice to have a helper package in go for testing purposes. Or is this introducing dependence's

I find myself repeating the same code when writing unit tests, for example... When writing functions that work with files, In the setup for the test i often write some code to create a file (in a ...
1
vote
3answers
127 views

What considerations should I mind when designing methods or functions that take in a lot of parameters?

What considerations should I mind when designing methods or functions that take in a lot of parameters? A lot meaning over 4 but less than 10. Example, I am debating whether to pass in an array like ...
1
vote
3answers
202 views

Use just one parameter for all dependencies instead of many?

I understand that having 3 or more parameters as dependency is a sign that the class may be doing too many things, however there are cases that the class really needs more than 3. My question is, is ...
51
votes
7answers
11k views

Managing and organizing the massively increased number of classes after switching to SOLID?

Over the last few years, we have been slowly making the switch over to progressively better written code, a few baby steps at a time. We are finally starting to make the switch over to something that ...
2
votes
1answer
281 views

FP Free Monad vs OOP Dependency Injection

I've written my first moderately large project in functional style (in F#) and can see the advantages. The main challenge was to achieve the "Onion" architecture i.e. large and "smart" pure core / ...
8
votes
5answers
1k views

When should we use dependency injection (C#) [closed]

I would like to be sure I understand the concept of dependency injection (DI). Well, I actually understand the concept, DI is not complicated: you create an interface then you pass the implementation ...
1
vote
4answers
173 views

Dependency injection / testability - would this logic be appropriate?

In a testability perspective, would this logic be appropriate? public class Foo { public List<SomeClass> Elements {get; set;} public Foo(IServiceInterface service) { this....
0
votes
3answers
433 views

Dependecy Injection vs Singleton Pattern

I just read documentation and tutorial about dependency injection (DI) and the singleton pattern (SP). Everybody seems to says DP is bad and DI is the way to do it. Tutorials about dependency ...
1
vote
1answer
91 views

Classes with lots of injected dependencies [closed]

I'm often finding that my classes end up with many (10-15) dependencies being injected. I realise there is no hard and fast rule, but someone once told me that more than 4 or 5 can be a code smell. ...
0
votes
1answer
144 views

Avoid too much dependencies for a Use Case in a Clean Architecture app

Context I'm currently developing an application following the Clean Architecture principles (at least I'm trying really hard to follow these). All my Dependency Injections are done manually, without ...
0
votes
1answer
184 views

Dependency injection: Is there a better way than new A(new B(new C ()))? [closed]

I'm just learning about dependency injection. Unfortunately, I don't have the luxury and time to learn a DI framework right now so I am attempting to do DI through some simple means. Say I have an ...
1
vote
1answer
100 views

How to define Composition Roots for libraries (Javascript/inversify)

I'm building a console app (A), which depends on library B. Library B further depends on library C. I am building all 3 entities. Most of the development completed so far has been done using a ...
2
votes
5answers
639 views

Can Dependency Injection be overkill?

At what point does dependency injection make sense? When I first learned about Guice I was really excited. I have a Concurrency module, which is basically just a singleton controlling concurrency. I ...
0
votes
2answers
277 views

Can I use a library that uses guice to bind contact and implementations in applications without issues?

I have a play application and want to take a common operation out from the application and make it as a library in order to use in other play applications. This proposing library has a contract(...
10
votes
5answers
2k views

Can we completely replace inheritance using strategy pattern and dependency injection?

For example: var duckBehaviors = new Duckbehavior(); duckBehaviors.quackBehavior = new Quack(); duckBehaviors.flyBehavior = new FlyWithWings(); Duck mallardDuck = new Duck(DuckTypes.MallardDuck, ...
6
votes
6answers
571 views

I need help solving a common architectural problem with multiple concrete classes implementing an interface

I have a common issue I encounter which I've solved with a Factory class in the past but it always felt a little "off". Let's say I have multiple Exporter classes which implement IExporter, which has ...
0
votes
2answers
463 views

Dependency Injection in C++ use pointer or object?

While I am learning C++ based on how develop in modern PHP frameworks I decided to use the Dependency Injection pattern with services as Singletons. For making myself clear let suppose we have the ...
3
votes
2answers
182 views

How should domain services be referenced?

I'm working on a test project, with the intention of using DDD. So far I have this basic project structure: My question is: How should the Core.Domain.Services be referenced? do I create an ...
1
vote
1answer
146 views

Avoiding instantiating the whole application at startup when using a composition root

In a typical non-DI application, when you enter a section of code the necessary objects are constructed and when you leave it they are deconstructed. However, when doing dependency injection with a ...
2
votes
2answers
224 views

Tight coupling between parent and children: always to be avoided?

Say we consider two inherently coupled elements, using a real-life like example: Body PhysicalIllness Note: the following code is pseudo-Java for the sole purpose of syntax-coloring, pure syntax ...
0
votes
2answers
193 views

Passing runtime-read configuration when working with an IoC container

I've recently "discovered" the IoC realm, and decided to refactor a project I'm working on to use such a container. To be specific - I'm using autofac in C#, in a .NET Core console application. The ...
2
votes
1answer
146 views

At what point is having a static class with utility methods better than having an injectable service?

I have a pretty general question about the design of Angular web applications. I'm a big fan of writing services. Sometimes I write services that have only utility methods that don't require state at ...
3
votes
1answer
208 views

Clean Architecture - Should you inject all entity dependencies?

According to "Clean Architecture", should you inject all entity dependencies (should you inject core business logic)? For example, if I have a vector entity, should that entity be injected into all ...
1
vote
2answers
461 views

When to use Factory design pattern instead of Dependency Injection?

I'm quite inexperienced in design patterns and while I was studying them I got confused about the application of the Factory pattern. Wouldn't DI decouple the classes more than factory would do it? Or ...
0
votes
0answers
138 views

Inherit a class that inherits a generic class to make it easier to read

I'm creating a simple Dependency Injection library for Unity (no constructors available) and I want to use a generic class that implements a generic call for each class that would inherit it allowing ...
0
votes
1answer
73 views

Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code below MyController //MyAction //MyHandler { public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); ...
11
votes
5answers
2k views

How to use dependency injection and avoid temporal coupling?

Suppose I have the Service that receives dependencies via constructor but also needs to be initialized with custom data (context) before it can be used: public interface IService { void ...

1 2 3 4 5 11