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.

37 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
2k views

Spring bean injection into a hibernate validator constraint

I have a controller method like listed below whose argument is annotated with @Valid to validate PasswordChange object using a Hibernate validator @Constraint. Both PasswordChange and a sample ...
ShaggyInjun's user avatar
3 votes
0 answers
878 views

Dependency injection - Nested objects

# Introduction I am working on a CMS application in PHP with about 200 classes. The CMS, in general, does the same thing every CMS does: generate sites. I am learning a lot about OOP and design ...
PIDZB's user avatar
  • 233
3 votes
0 answers
2k views

Dependency Injection and class Inheritance

The project I am working on for about a year now was used to create a new mysqli connection to the database each time there was a Query to the database. In order to quickfix this problem at places ...
Tekay37's user avatar
  • 235
3 votes
0 answers
556 views

Mocking third party web service

I am working on a project to create a wrapper library which will be used to interact with a web service provided by the client's IT team. The reason for this library is that we interact with this ...
DFord's user avatar
  • 1,240
3 votes
0 answers
692 views

State Pattern Code for embedded device - Dependency Injection of Device Objects in Context and State Classes

I'm wrestling with some code and I think I've finally gotten some state pattern code working with my events. I've got a simplified system that will work like this: This is my first go with State ...
GisMofx's user avatar
  • 379
3 votes
0 answers
358 views

Manual dependency injection or abstract factory

We're starting to use dependency injection in a fairly large, interactive program. It's early yet, but I have a feeling that the majority of the objects being injected are going to want runtime data ...
donkey's user avatar
  • 139
3 votes
0 answers
784 views

ASP.NET Mvc3 - application/request lifetime and dependency injection

I thought of asking on SO, but it seems this is more of a "concept" type question than a "problem" type question. If it needs to be moved, please do so. Anyway, I'm having a tough time finding ...
Ivan Pintar's user avatar
  • 1,187
2 votes
0 answers
304 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 ...
catfood's user avatar
  • 1,615
2 votes
0 answers
148 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 ...
Kelley van Evert's user avatar
2 votes
0 answers
58 views

Better approach of testing groups of small services with or without dependency injection

Let's assume, that frameworks I use, provide some kind of dependency injection automatically available in testing environment. Let's also assume, that I have a lot of micro services in my application....
mpasko256's user avatar
  • 336
1 vote
0 answers
1k views

WPF Best way to create viewmodel from another viewmodel

Often I want to open a new window from within some view. I see opening a window as view logic. So I don't want code in my viewmodel that creates/opens/changes windows or anything else that interacts ...
user2190492's user avatar
1 vote
0 answers
249 views

Microservice code reuse strategy for static classes

Hope this is the right place to post an opinion-based question like this. I'm in the process of converting an aging API monolith to a set of .NET 5/C#-based microservices and working on the code reuse ...
JTennessen's user avatar
1 vote
2 answers
530 views

Angular 7 - Injecting a State/Context Snapshot

Requirement There is some (for arguments sake) “global” application state that I am interested in injecting into components. Each candidate component should receive an immutable snapshot of the ...
Bryce Marshall's user avatar
1 vote
0 answers
130 views

How can I load service dependencies into model classes?

My model objects are generated by the library using hard-wired new operators, which makes dependencies injection using the constructor impossible. However, they also have methods, which are called by ...
Michael Tsang's user avatar
1 vote
0 answers
581 views

Opening new Window from ViewModel using Castle Windsor

I've been following the quick tutorial on using Castle Windsor in MVVM WPF: TUTORIAL I've set everything up (as for the basics) but I came to the point of creating a new Window after a button click. ...
Kamil Solecki's user avatar
1 vote
0 answers
530 views

Dependency Injection with global objects (sessions)

TL;DR: My question is about how to use in conjunction: the dependency injection design pattern with global / immutable objects (ex: a session that references a customer object) I get the idea of ...
Joseph at SwiftOtter's user avatar
1 vote
0 answers
140 views

disadvantages of classpath-based dependency injection for testing

DI frameworks like Guice and Spring are the common tools to abstract out dependencies to make Java code testable. However, there are several alternate methods to achieve the same goals. One in ...
Reinstate Monica's user avatar
1 vote
0 answers
61 views

Dealing with stubbed external dependency

In sut I should I have two kinds of dependencies to be stubbed: 3rd party dependencies (mongodb & co) and own dependencies: var async = require('async'), // This dependency should not be stubbed ...
hellboy's user avatar
  • 141
1 vote
0 answers
231 views

How to clean composition root from anything other than object construction?

I'm doing poor man's DI (manual injection) in my application. My (pseudo-) composition root looks something like this: var connectionSettings = new Settings(SqlParameters) var dataLoader = new ...
jqer's user avatar
  • 11
1 vote
0 answers
555 views

Am I following a good design thought process? Is the Abp framework overkill?

As I finish one project and start another, I have a small time window to come up with an architecture for the new. I am coming from the following design: Web applicationReceives domain models & ...
tacos_tacos_tacos's user avatar
1 vote
0 answers
275 views

Single write, multiple read of stateful objects

Scenario: One data input feed (call this Source) Multiple objects (call these Layer1) read this Source, and analyze the feed. This analysis is stateful. Layer1 objects have configuration parameters. ...
durron597's user avatar
  • 7,600
0 votes
0 answers
135 views

better structure of a software project to prevent circular dependencies

I am contacting you today regarding a recent problem with circular dependencies. It's about a Spring boot application that accepts data via a Rest API and then forwards it to an internal Spring ...
Phoenix's user avatar
  • 29
0 votes
0 answers
137 views

Dependency Injection Usage

I'm very new to DI, and must admit, am having a hard time understanding to what extent it should be used in an application. Even in a basic project, you can have hundreds of classes that have ...
wforl's user avatar
  • 19
0 votes
0 answers
126 views

How to handle dependency injection in a library to avoid frequent breaking changes?

Let's say I have a C# .NET library with the following classes: public class FooService { private readonly IDependencyA a; public FooService(IDependencyA a) { this.a = a; } ...
srk's user avatar
  • 127
0 votes
0 answers
137 views

Best practices when it comes to extending Service collections in .NET for dependency injection

Most of the information that I can find online is about how to do basic dependency injection in the common flows. eg one DI container where services are registered. For a project we are writing a ...
Robin's user avatar
  • 103
0 votes
0 answers
51 views

Dependency Injector and Collections

I have been searching for an answer in this topic but I haven’t been able to find a satisfactory one like in other topics, where the consensus is solid. The situation To keep things simple: I am ...
Demolition Architect's user avatar
0 votes
0 answers
101 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 ...
qkhanhpro's user avatar
  • 131
0 votes
0 answers
326 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 ...
Valuator's user avatar
  • 101
0 votes
0 answers
2k 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 ...
Javier Bullrich's user avatar
0 votes
0 answers
160 views

Is using IoC with data classes a good practice

I usually use IoC frameworks to inject dependencies that are services. Is it ok to mark classes that are data objects as IoC components? To be more clear I will give an example. I have an abstract ...
Mikołaj Mularczyk's user avatar
0 votes
0 answers
599 views

WPF DI with DbContext per form

Trying to figure out how to keep class methods clean, follow EF's guidance of short-lived DbContexts, and use DI in WPF. Issue I'm having is implementing transactions with DI. I'm trying to figure ...
keelerjr12's user avatar
  • 1,219
0 votes
0 answers
104 views

Manual DI and Managing Concrete Implementations

Considering a solution that has some manual DI going on such as the below class, is there a better way of managing the concrete implementations without adding a container. This is theoretical, there ...
Lotok's user avatar
  • 1,769
0 votes
0 answers
418 views

Dependency Injection with EF - is mapping required?

I'm implementing the Repository pattern with using DI and EF6. I created the database (that inherits from DbContext) object with the Visual Studio wizard ADO.NET Entity Data Model I have a generic ...
fra9001's user avatar
  • 121
0 votes
0 answers
2k views

Are prototype beans with constructor parameters an anti-pattern?

Reading on this, Misko Hevery has said “Newables can ask for other Newables in their constructor, but not for Injectables” Now it appears to me that requesting a prototype be instantiated at run-time ...
blindcodifier9734's user avatar
-1 votes
1 answer
780 views

IOC principle - Servlet container implementation

IOC principle can be implemented, using either: Dependency Injection Service locator pattern This article also supports these two approaches for implementing IOC principle. Spring IOC container is ...
user1787812's user avatar
-1 votes
3 answers
426 views

Refactoring - Resolve dependencies between legacy code used by third parties

I am developing two libraries in .Net Firs one it's a library with core functionality (named it Library.Core.dll) Let's focus in User class public class User { //set of constructors and ...
X.Otano's user avatar
  • 622
-1 votes
3 answers
832 views

Factory needs list of available objects. Should it be static or not?

I have a list of IReader that I read at the beginning of my program. Later on I need ReaderFactory to get appropriate IReader based on Extensions it can use. The problem is the factory needs to know ...
FCin's user avatar
  • 522