Questions tagged [dependency-injection]
Design pattern to reduce coupling between components, by dynamically injecting into a software component dependencies that it needs to function.
262
questions
2
votes
1
answer
37
views
Databases, dependency injection and static methods
I'm working on a Next.js app and looking at the best way to structure database access. With Next.js and web based apps in general, there are lots of different "server actions", aka, API ...
4
votes
2
answers
103
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 ...
2
votes
2
answers
216
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 ...
1
vote
0
answers
53
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 ...
1
vote
0
answers
107
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 ...
0
votes
1
answer
99
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....
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 ...
2
votes
1
answer
324
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 ...
4
votes
2
answers
227
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 ...
1
vote
1
answer
255
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 ...
4
votes
0
answers
97
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
...
2
votes
0
answers
179
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 ...
3
votes
0
answers
206
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 ...
4
votes
0
answers
118
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 ...
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 ...
1
vote
0
answers
775
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 ...
2
votes
1
answer
361
views
Dart Ioc Container
This package is on pub dev here
It's on Github here
...
1
vote
2
answers
889
views
Configure lazy and non lazy DI for automapper
I have the following code to register the dependency injection for automapper:
...
0
votes
1
answer
127
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 ...
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 ...
0
votes
1
answer
496
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 ...
1
vote
0
answers
126
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 ...
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 ...
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 ...
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.
...
4
votes
2
answers
189
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 ...
1
vote
0
answers
103
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 ...
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 ...
2
votes
1
answer
96
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....
0
votes
0
answers
249
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 ...
2
votes
0
answers
539
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 ...
3
votes
2
answers
758
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 ...
2
votes
1
answer
246
views
Determine dependency injection type at runtime from config
I have a .NET application with a .config file that has content like this:
...
3
votes
1
answer
968
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 ...
1
vote
0
answers
427
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. ...
-4
votes
1
answer
245
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:
...
1
vote
1
answer
181
views
Service Locator with Lazy Loading in Swift
I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items.
...
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 ...
4
votes
1
answer
626
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 ...
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 ...
-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 ...
0
votes
1
answer
83
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 ...
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 ...
5
votes
2
answers
643
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 ...
3
votes
0
answers
134
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 ...
3
votes
1
answer
910
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 ...
1
vote
1
answer
601
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 ...
5
votes
0
answers
130
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 ...
5
votes
0
answers
305
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-...
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....