Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take 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
2 votes
0 answers
159 views

Dart Ioc Container

This package is on pub dev here It's on Github here ...
user avatar
0 votes
0 answers
26 views

Resolver Factory Pattern for IoC in an Asp.Net 6 Web Server

I'm currently testing an experimental IoC pattern enabled by a factory implementation, currently implemented for use in an Asp.Net 6 web server. The pattern is intended to support lazy resolution of ...
user avatar
  • 1
0 votes
0 answers
33 views

Abstract instance creation for handler

My application uses several data sources. One is a web-service, the other uses a database context, and in some cases even files on servers have to be retrieved. I am trying to find a way to ...
user avatar
1 vote
1 answer
36 views

Configure lazy and non lazy DI for automapper

I have the following code to register the dependency injection for automapper: ...
user avatar
  • 631
0 votes
1 answer
51 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 ...
user avatar
3 votes
0 answers
74 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 ...
user avatar
  • 43.8k
0 votes
1 answer
96 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 ...
user avatar
0 votes
0 answers
84 views

ASP.NET Core dependency injection in class library with params

I know this question could be the new variant of other 1million questions but before you say that, let me explain what I'm trying to achieve. I have a lot of APIs and want to create an SDK. There is ...
user avatar
1 vote
0 answers
40 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 ...
user avatar
0 votes
1 answer
256 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 ...
user avatar
2 votes
1 answer
817 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 ...
user avatar
  • 301
1 vote
2 answers
185 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. ...
user avatar
  • 807
4 votes
2 answers
175 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 ...
user avatar
1 vote
0 answers
44 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 ...
user avatar
-1 votes
1 answer
43 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 ...
user avatar
2 votes
1 answer
79 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....
user avatar
1 vote
0 answers
40 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 ...
user avatar
  • 11
2 votes
0 answers
321 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 ...
user avatar
3 votes
2 answers
378 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 ...
user avatar
  • 132
1 vote
0 answers
2k views

.NET Core Dependency Injection - Worker Service x Web Api [closed]

Folks, I have a big question about how .NET dependency injection "native/default" works on a Service Worker scope. We need to resolve a service(...
user avatar
  • 202
2 votes
1 answer
106 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
user avatar
2 votes
1 answer
393 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 ...
user avatar
  • 121
1 vote
0 answers
110 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. ...
user avatar
-4 votes
1 answer
77 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: ...
user avatar
1 vote
0 answers
35 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 ...
user avatar
  • 111
1 vote
1 answer
102 views

Service Locator with Lazy Loading in Swift

I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items. ...
user avatar
  • 113
4 votes
0 answers
98 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 ...
user avatar
  • 141
4 votes
1 answer
356 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 ...
user avatar
  • 294
1 vote
1 answer
53 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 ...
user avatar
-2 votes
2 answers
95 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 ...
user avatar
  • 121
0 votes
1 answer
77 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 ...
user avatar
5 votes
1 answer
8k 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 ...
user avatar
6 votes
2 answers
461 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 ...
user avatar
  • 161
3 votes
0 answers
65 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 ...
user avatar
3 votes
1 answer
410 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 ...
user avatar
1 vote
1 answer
94 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 ...
user avatar
5 votes
0 answers
107 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 ...
user avatar
  • 211
5 votes
0 answers
176 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-...
user avatar
10 votes
0 answers
872 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....
user avatar
  • 7,673
3 votes
1 answer
180 views

Grouping low-level services together into a high-level service

I am working on an e-commerce website. What I need to do is to save an advertisement. The ad has some properties and some photos... properties should be save to DB and photos should be saved to file ...
user avatar
4 votes
1 answer
185 views

OOP Dependency inversion principle VBA

I've reproduced the example of this video where dependency inversion principle is explained by Tim Corey based on C# I had some trouble understanding the scope of the Logger and MessageSender ...
user avatar
3 votes
1 answer
140 views

ASP .NET Core DI: Dependency on single implementation of multiple registrations of service type

Problem I have a DI scenario where I have multiple classes that implement a common interface (IModelService). I'm using a generic framework class (...
user avatar
  • 139
0 votes
0 answers
77 views

Extremely lightweight dependency injection

I need to have access to a set of common data inside a few functions. The data values are determined only at runtime, and are far away in terms of control flow, so handing them to the function as an ...
user avatar
  • 117
4 votes
2 answers
335 views

C# Cryptography Interface

C# lacks a common off-the-shelf encryption and decryption interface for dependency injection. Nearly every codebase I've ever opened has a couple of extension methods for hashing strings and so on. ...
user avatar
1 vote
0 answers
27 views

Usage of global variable for dynamic value that must be declared compile time [closed]

I've been trying to make a work-around for global usage; however, I can't seem to find an alternative. I'd like to create a C++ suffix function which converts pixels to millimeters. A custom gui ...
user avatar
1 vote
0 answers
50 views

How should I instantiate a class using composition with Laravel IOC container? [closed]

I have an Analytics class that performs some actions to compile analytics data. Here is that class: ...
user avatar
3 votes
0 answers
106 views

HTTP Delete,Put,Get,Post REQUEST java-ee RESTful services JPA CDI EJB

I am creating introduction app to java ee and APIs of java ee and i want know if my code is ok (like its working but if it could be done better) and what should i avoid in future ...
user avatar
1 vote
1 answer
591 views

Creating a ModelBinder to Sanitize user input in HTML format

I have a custom model binder which takes user input in HTML format, sanitize the HTML input by removing any script or XSS threat and returns the sanitized HTML string: ...
user avatar
2 votes
3 answers
440 views

Simple middleware pipeline builder (similar to asp.net-core)

I created a simple middleware pipeline builder that I want to use for my frameworks. It is similar to how ASP.NET-Core middleware works and uses the same conventions: A public constructor with a ...
user avatar
  • 43.8k
-1 votes
1 answer
81 views

Using Dependency Injection through constructor [closed]

I am working on a asp.net mvc project. And I wonder if the setup of the project is correct. So just some advice Because I see this: ...
user avatar

1
2 3 4 5 6