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
0
votes
1answer
128 views

Is it ok to Inject a whole object instead of only the dependencies

I'm working with the Dependency Injection Pattern in Unity3D (an engine which uses MonoBehavior, a class that doesn't have a constructor, as the base class for all of its game components), and I ended ...
2
votes
1answer
95 views

Changing a class with static dependency injection to allow unit testing

I'm new to JUnit/Mockito and to unit testing in general. I'm asking this question in order to get feedback and learn best practices/patterns/strategies. I wrote a class but when came time to unit test ...
0
votes
3answers
128 views

How to choose between these different options for communicating between objects?

I have a few objects that should communicate between each other. I also want to have my code unit tested. I am questioning how I should handle their communication: Should I make one instantiate the ...
0
votes
0answers
47 views

Cross-cutting concerns and dependency injection

I've got a web application with an architecture somewhat like a front-controller MVC design. I get HTTP requests, route them, run them through a filter layer, dispatch them to my domain classes which ...
0
votes
1answer
55 views

Load single module based on configuration using dependency injection

I'm working on an application that will run on multiple systems and may use different modules to communicate with external systems, but on each system, only one module will be used at a time. As it ...
-3
votes
2answers
77 views

Dependency access control in DI

As I'm just getting into ASP.NET Core, I'm also continuing to slowly learn about Dependency Injection and still trying to identify some value in it for our practical purposes. The point I've reached ...
0
votes
2answers
78 views

Default value for constructor dependency injection

I have class A that depends on interfaces B & C. I use constructor injection to inject them into A: class A { let b: B let c: C init(b: B, c: C) { self.b = b self....
2
votes
3answers
172 views

Why is global state not considered as an example of dependency injection?

According to Why is Global State so Evil?, as I understand, global state is bad and I should use dependency injection instead. That means, for example, a mobile app that use bundles of app level data ...
-1
votes
2answers
119 views

How to use Dependency Injection on repositories in Generic Repository Pattern with base class inheritance

How to dependency inject repositories that inherit an abstract class (that inherits another abstract class) which implements the interface? I will give you a simplified version of my current ...
0
votes
0answers
50 views

Conditionally filtering dependency-injected async data?

I have a NodeJS application which I've built around dependency injection. The app can run any combination of its functions (modules) at the same time, and any modules that request data from the same ...
5
votes
2answers
285 views

How to clean up a business logic class that does too many things without injecting a ton of classes into it?

Let's say we have business logic to perform in an MVC framework after a user submits a form: class BusinessLogic: def sendDataTo3rdPartyApi(self): # do stuff def validateResponse(self)...
3
votes
2answers
139 views

Refactoring for removing explicit object construction inside class

I'm wondering if there's a standardized name for the following refactoring: class Foo: def do_something_awesome(self): my_bar = Bar(42) return my_bar.reticulate_splines() Here class Foo is ...
0
votes
1answer
114 views

Mixing IoC container use with “poor mans” DI

I'm finding the use of IoC containers to be quite the shift in my application design, and its for the better. I'm using a framework called injector that aims to mimic (albeit not entirely) the Guice ...
3
votes
2answers
170 views

How to avoid DI dependency cycle for observer pattern

In my project I'm using the observer pattern in several places, i.e. the subject notifies the observers about something, and expect them to act. The subject does not know anything about the details of ...
1
vote
2answers
136 views

Is passing arguments to a constructor always considered DI?

Starting to explore using DI more in my project design and I find myself asking the same question: "If I pass this object to that constructor, does that new object now have a dependency?" For ...
0
votes
1answer
59 views

Is coupling functionality desired when the usage of a function can be predicted with near-perfect confidence?

I have a function whose job is to look through a string that is a post's content and find certain pieces: public static function findInsidePostContent( $post = Null ) { //post_content comes from ...
0
votes
3answers
116 views

Unit Testing: Constructor Injection with Fake Objects - Bad Tests?

In The Art of Unit Testing, 2nd Ed., the author gives the following example for injecting a stub using constructor injection and a "fake object". The goal of the "fake object" is to inherit the ...
3
votes
3answers
452 views

Design pattern: How to inject dependencies into a Command pattern

I am pretty new to programming languages and only have limited knowledge about design patterns, so I hope you can help me with the following problem: I have an application that operates on a group of ...
0
votes
0answers
13 views

Organizing spring profile : specific case with unit test and multi module

This could be viewed as a follow-up of Organizing maven modules and spring profiles with a more specific case. I currently have an application with a GUI (mix of Swing for Cartography/JavaFX/Spring). ...
0
votes
2answers
59 views

Usage of objects as services in static functions

The goal within my framework is to provide facades or front-facing functions/APIs so that people can easily interact with my system, as such, in most cases, that goes super well by having static ...
0
votes
1answer
202 views

Android project, clean architecture and modular approach

I have this project with MVVM and clean architecture well implemented but I've decided to split it into modules. Right now I have: apimodule apimodule: with the retrofit dependencies app: with the ...
1
vote
2answers
161 views

Avoid class chains that emerge from DI

I am developing a hobby project where I try to use DI to get testable code. Until now, I found that it improved both the readability, usability, and testability of the code. However, now I have a ...
2
votes
4answers
508 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
113 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
232 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
249 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
328 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
48 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
75 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
60 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
116 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
184 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
121 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
183 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
180 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
66 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
68 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
274 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
306 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
284 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
181 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
270 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
124 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
77 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
129 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
203 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 ...
3
votes
1answer
377 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 / ...

1
2 3 4 5
12