Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [dependency-injection]

Design pattern to reduce coupling between components, by dynamically injecting into a software component dependencies that it needs to function.

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

Choosing Between Field Injections and Constructor Injections for Modular Java Applications with Spring Boot

I'm six months into a Java training program and have developed a Spring Boot application, adhering to Java's separation of concerns principle. I've organized my application with distinct sections for ...
Kerem Tazedal's user avatar
2 votes
2 answers
209 views

How can I design the configuration of the library with Typed HttpClients in DI better?

I have written a .Net Client wrapper for Google Gemini (Generative AI) REST API and published it as a Nuget package. I am seeking a review of the code. I have spent quite some time in designing how it ...
Junaid's user avatar
  • 137
1 vote
0 answers
52 views

C# like Dependency injection for C++ on embedded device

I was wondering if it would be possible to create a C# like syntax for dependency injection. My device is running constantly and acting more or less like a service. I came up with the following. My ...
Bas Visscher's user avatar
1 vote
0 answers
102 views

PHP implementing Dependency Injection

I'm trying to implement Dependency Injection in one of my projects. It's a project that when I started I didn't had much experience with sotware development, but now I feel like it's time to do a bit ...
CelsomTrindade's user avatar
0 votes
1 answer
96 views

A practice program to manipulate a database table using dependency injection [closed]

I am learning dependency injection and trying to use this pattern on practice. I am trying to write simple program where the user can write something to database, delete row and clear all rows from db....
Денис Шпак's user avatar
2 votes
1 answer
147 views

Saving entity containing complex jsonb column with validation and comparision

I've been a .NET Developer for almost 4 years. I'm stronly learning and trying using design patterns and following SOLID principles for 3 months right now (I know - a little late, but better late ...
KJanek's user avatar
  • 123
2 votes
1 answer
318 views

An NVIDIA Jetson Nano GPIO Wheel Encoder Message Publisher using ROS2

Although this code uses ros2 my concern is about C++ code quality, because I still struggle when it comes to making good design ...
Sam Hammamy's user avatar
4 votes
2 answers
225 views

Automating the process of determining which boxes to load on each flight for freight company

I was given a test assignment for the interview of the company and below is the code that I shared with them. I developed it using .NET 6 (Core) Console application. Actual problem statement: Coding ...
user19031158's user avatar
1 vote
1 answer
253 views

API call to list top stories using dependency injection in iOS with MVVM

I'm currently trying to find out what's the best networking architecture for MVVM applications. I couldn't find many resources and decided to go with dependency injection based architecture as per the ...
Tharindu Ketipearachchi's user avatar
4 votes
0 answers
96 views

Determine when a file is no longer being changed by hashing

I have a requirement to essentially scan a filesystem on any kind of filesystem and move a resource whenever it is ready. To do this I have the following code ...
Patrick Christie's user avatar
2 votes
0 answers
177 views

Android architecture and dependency injection of domain layer usecases

I am implementing some of the architectural designs from Google I/O's app to my own app, but I have come across something in their app that has created some confusion for me. They have a domain layer ...
CJR's user avatar
  • 151
3 votes
0 answers
205 views

Simple Java IoC container for dependency injection

I have come up with a quick and simple IoC container to enable minimal dependency injection support in one of my Java projects. The container supports services with: A transient lifetime, meaning, a ...
Amal K's user avatar
  • 173
4 votes
0 answers
114 views

Injectable EventLogger for custom application events that are handled differently from normal logs

I am trying to become better at designing classes for dependency injection and IOC in general. It is often not an intuitive concept. I have the following python interface and implementation for a ...
Patrick Christie's user avatar
1 vote
0 answers
84 views

Hashing service for files or directories on a generic filesystem [closed]

my program requires a hash to be generated for files and folders for data integrity between transfers and file system events (if hash is different, file is not ready). For data integrity, I wish to ...
Patrick Christie's user avatar
1 vote
0 answers
757 views

Hangfire context constructor injection

I tried following IHttpContextAccessor pattern but for Hangfire context. What I'm mostly interested in is CustomScope class with Resolve method. I'm using ActivatorUtilities there because otherwise I ...
Medo's user avatar
  • 111
2 votes
1 answer
358 views

Dart Ioc Container

This package is on pub dev here It's on Github here ...
Christian Findlay's user avatar
1 vote
2 answers
866 views

Configure lazy and non lazy DI for automapper

I have the following code to register the dependency injection for automapper: ...
Pete's user avatar
  • 641
0 votes
1 answer
123 views

Image scraper using Dependecy Injection in Rust with generics

I'm writing a scraper that downloads images from a given subreddit. I'm new to Rust, and in the majority of my previous projects I was using C++ or Java, where it's easy to do Dependency Injection. I ...
aurelia's user avatar
  • 103
3 votes
0 answers
95 views

Handling boilerplate tasks via service pipelines

Here's a small experiment about handling boilerplate tasks via service pipelines. It's similar to the HTML pipeline but simpler and multipurpose. I've updated the question and this is the 2nd version ...
t3chb0t's user avatar
  • 44.3k
0 votes
1 answer
491 views

Generic Base Repository implementation with Unit of Work in C#

I have seen a lot of Repository pattern implementations with Unit of Work. The simplest way of implementing this I came across is using hard-coded repos (such as this one), while the way recommended ...
oneManArmin's user avatar
1 vote
0 answers
124 views

Injecting dependencies in Flask routes without a DI framework

I was wondering what might be the best way to inject Flask routes dependencies without a DI framework. I came up with something like this (CalculationService being ...
barciewicz's user avatar
1 vote
1 answer
3k views

Using the repository pattern with Dapper and a single accessor object

We are using Dapper as our ORM and have chosen the repository pattern for organizing our operations. This has worked very well for us but I'd like to confirm that this configuration is capable of ...
Adam Chubbuck's user avatar
2 votes
1 answer
5k views

Polly AddPolicyRegistry() with factory and registered dependency injection service instances?

The Microsoft.Extensions method for Polly, to use policies via dependency injection, serviceCollection.AddPolicyRegistry() only allows to add already created ...
Erik Hart's user avatar
  • 301
1 vote
2 answers
4k views

Configure service with user-related parameters in .NET Core dependency injection

I have service class which loads data from external service. This service needs API key which loads from db and unique for every user. ...
sDima's user avatar
  • 849
4 votes
2 answers
187 views

CGI script that reads or writes its height and weight configuration

UPDATES: I'm looking for an answer that can answer the questions listed in the post. Moreover, this answer will not only continue my way of thinking, but also give feedback based on it. It's just like ...
Andy Lin's user avatar
1 vote
0 answers
102 views

Replace SingletonPattern by using IOC Container based architecture

I have a legacy winForms application that now I'm in charge of maintaining and developing. This app has a lot of singleton instance.... Some are very similar to service that wrap other component or ...
Federico Borghesi's user avatar
1 vote
1 answer
245 views

Better way to keep a list of items from a Http Request?

I have a simple web api where each request "item" is stored in a list and thus a list is built without creating a new list per request. I have achieved this via dependency injection , but I ...
BigAl1992's user avatar
2 votes
1 answer
95 views

Asp.Net overall design pattern integrating REST, dependency injection, and Hosted Services (See full project at Github)

I'm new to C#, and want to conform as much as possible to good design patterns. This code is the beginning of a Microservice, running as Asp.Net. It is based on a Microsoft tutorial doing similar work....
RightmireM's user avatar
1 vote
0 answers
246 views

Handling sessions in SignalR core

I am using .Net 5, and I am making game server using SignalR core. Ther're 2 ways to inject service to my classes. 1- Constructor injection: where I must separate functions and data, even if it's ...
Adam Q's user avatar
  • 11
2 votes
0 answers
530 views

How to use single child Unity container for OWIN middleware and WebAPI

I am using OWIN to self host a WebAPI service. There is Unity to serve as an IoC container. Within several OWIN middlewares (e.g. authorization layer) as well as in WebAPI I need to access a Unity ...
Ondra Netočný's user avatar
3 votes
2 answers
750 views

Simple constructor DI implementation in Rust

From my experience in C# programming I think that DI is important. But it's not possible to do it same way in Rust. There are some DI frameworks but I've come with an idea on how it can be made and ...
Vlad's user avatar
  • 132
2 votes
1 answer
245 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
Michael Brandon Morris's user avatar
2 votes
1 answer
952 views

Inversion of control in Rust

I'm working on my first Rust project of any particular size, a rudimentary IRC bot. So far I've found solutions to most of the problems I've encountered, but something I'm now getting tangled up in as ...
Mikkel's user avatar
  • 121
1 vote
0 answers
426 views

ILogger with Delegate Callback

My code writes data and then receives data back. I want to log that this has happened, and I also want to inject a delegate so that I can get a callback to trace the data that is going in and out. ...
Christian Findlay's user avatar
-4 votes
1 answer
242 views

Creating a Constructor used only for testing: anti-pattern? [closed]

I have a class which uses the Azure SDK. The class has two constructors, shown in pseudo code below: ...
FoxDeploy's user avatar
1 vote
0 answers
81 views

Typescript Express - Controller in Controller via dependency Injection or logic in routes

I'm trying to give one Controller one operation. However, some Controllers exists of 2 or more operations. I'm not sure whats the best way to structure this part of the app. For example, I have 2 ...
Dusty48's user avatar
  • 111
1 vote
1 answer
179 views

Service Locator with Lazy Loading in Swift

I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items. ...
Teddy K's user avatar
  • 113
4 votes
0 answers
200 views

Sharing User Inputs via Dependency Injection

This code solves the problem of how to share user inputs throughout a large application when using dependency injection. To achieve this, I'm using a static (through DI) store and injecting it at ...
David's user avatar
  • 141
4 votes
1 answer
617 views

Configuring NavigationService and NavigationView in one place

Context The main goal located a configuration NavigationService and NavigationView in one place. In order to minimalization a ...
Viewed's user avatar
  • 294
2 votes
1 answer
121 views

DI container with auto-wiring feature

So I decided to write my own DI container for educational purposes and would like some feedback on how I can improve the quality of my code. I'm not sure about the documentation as most of my ...
Josh Hallow's user avatar
  • 1,345
-2 votes
2 answers
108 views

Episode 1: Mastering code and Testing it [closed]

Once upon a time there was a noob developer who learned it all by himself because he grew up in a nation far behind in IT. I've tried to learn C# for about 5 years, without any improvement over the ...
exSnake's user avatar
  • 121
0 votes
1 answer
82 views

Console Commands with dependency injection (C#) [closed]

So I'm writing a big server and I've made a simple start on console commands. I'm not sure if the way I'm doing it in is correct so I'd like to have it reviewed. I have a class called ...
Gabrielle X's user avatar
5 votes
1 answer
14k views

Dependency Injected StackExchange.Redis Client

I am currently building cache for my application, and I would like to have my redis cache client work the same way you would dependency inject a DbContext. I am using StackExchange.Redis to manage my ...
Thorbear's user avatar
5 votes
2 answers
635 views

ASP.NET Core Web API + Pure DI

I was playing around with ASP.NET Core 3.1 and tried to implement Dependency Injection flavor called Pure DI, i.e. without dependency container (even the built in one) to instantiate Controllers. You ...
Piotr's user avatar
  • 151
3 votes
0 answers
132 views

Functional Dependency Injection Abstraction

The F# web-development framework Giraffe supports a functional style of Dependency Injection using a form of the Reader monad, as explained in this GitBook. I would like to use this pattern more ...
Aaron M. Eshbach's user avatar
3 votes
1 answer
887 views

C# REST / Http Client Abstraction

I have a REST library. These are the abstractions. Have I missed anything that a developer would need to use this in a dependency injection / IoC Container scenario? Anything that bothers you about ...
Christian Findlay's user avatar
1 vote
1 answer
600 views

A Class to Supply an Open Database Connection during the life of a Web Request

For some database requests, I like to use raw ADO.NET. In the context of a web request, I have created a class which provides an open IDbConnection object. I use ...
onefootswill's user avatar
5 votes
0 answers
127 views

Production planner

I have a class that creates an object, PlannedYear, and then passes that object into several other classes to manipulate it. The ultimate goal of the class is to ...
MSOACC's user avatar
  • 211
5 votes
0 answers
300 views

Using ClientFactory-pattern with Dependency Injection

I initially posted this on Stackoverflow but was recommended to try here instead. I'm looking for feedback on why the implementation of my ClientFactory is probably bad, from a Dependency Injection-...
Rasmus Westerlundh's user avatar
10 votes
0 answers
2k views

Geode Contents Predictor StardewValley Mod

The goal I really enjoy the game Stardew Valley. One of the things that the game has are geodes. Much like real-world geodes, these geodes can be cracked open, and you can find some fun things inside....
Dan Oberlam's user avatar
  • 7,804

1
2 3 4 5 6