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
-1
votes
1answer
37 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
1answer
64 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
0answers
17 views

Using Autofac with static services class

I am using Autofac to maximise the sharing of code between Android and iOS via a shared PCL assembly in a Xamarin (native) environment. The shared service layer consists of four interfaces to classes ...
0
votes
0answers
14 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
0answers
122 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
2answers
118 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 ...
1
vote
0answers
732 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(...
2
votes
1answer
44 views

Determine dependency injection type at runtime from config

I have a .NET application with a .config file that has content like this: ...
1
vote
1answer
157 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
0answers
58 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
1answer
53 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
0answers
34 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 ...
1
vote
1answer
66 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
0answers
62 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
1answer
200 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 ...
1
vote
1answer
49 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
2answers
93 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
1answer
75 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 ...
3
votes
1answer
4k 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
2answers
296 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
0answers
52 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 ...
2
votes
1answer
167 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
1answer
63 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
0answers
104 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
0answers
130 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-...
9
votes
0answers
430 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....
3
votes
1answer
169 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 ...
4
votes
1answer
137 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 ...
3
votes
0answers
111 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 (...
0
votes
0answers
76 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 ...
4
votes
2answers
215 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. ...
1
vote
0answers
26 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 ...
1
vote
0answers
34 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: ...
3
votes
0answers
83 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 ...
1
vote
1answer
256 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: ...
2
votes
3answers
286 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 ...
-1
votes
1answer
78 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: ...
4
votes
2answers
118 views

Registering Named services and resolving them by T

Problem statement I have an application that needs to get files from various sources (disk, embedded, http, ftp, ...) so I use a common API for them: ...
2
votes
0answers
76 views

Swift MVVM: Repositories - loading entities and dependency injection

I create a lexikon and a navigation for ZOO. I use MVVM architecture supported by ReactiveSwift. I have a few questions about my practises and whether I could write my repositories better and more ...
1
vote
1answer
426 views

Do these BLL-DAL comply with the Dependency-Inversion Principle and is this valid Dependency Injection?

I am working on a very simplified proof of concept (POC). Separation of concerns should be achieved in this project, so that in the future we have flexibility in respect of what data source we use (...
3
votes
0answers
81 views

Using functional interface arguments in methods of services injected via Spring

Here is the working code for my Spring service: ...
1
vote
0answers
67 views

Tightly coupled Basic Authentication Filter

I have an asp.net web api and I would like to use basic authentication. Is there any way to make this loosely coupled? I tried constructor DI but I couldn't figure it out how to pass Dbcontext into ...
1
vote
2answers
162 views

Wrapper class for system dialog to allow for dependency injection

The following class is a wrapper for Microsoft.Win32.SaveFileDialog. I've implemented the usage of Microsoft.Win32.SaveFileDialog...
2
votes
0answers
655 views

Ninject binding for Dbcontext

I have an asp.net web API and I am using EF6 to connect to a third party rest API which sells online game codes. We made a deal with the company so clients have to call my rest API in order to get the ...
4
votes
3answers
99 views

Dependency injection in constructor vs Supplying argument in utility functions

I have the following: ...
3
votes
0answers
260 views

Create an isolated dependency scope with “overrides” in Asp.Net Core

Some of the classes in my multi-tenant Asp.Net Core application depend on database repositories which in turn depend on a delegate called GetCurrentTenantKey. In ...
2
votes
1answer
1k views

Include Serilog sink requiring dependency before dependency injection in .NET Core

Here is a rundown of the situation This is a .Net Core (2.1) application with a console and web front ends. For simplicity this question focuses only on the console end although the web end has the ...
5
votes
0answers
768 views

Auto register Func<T> for .net core dependecy injection

The default .net core dependency injection doesn't support building Func<> for injection automatically, see question. I wrote an extension method to go find all the Func in register types ...
4
votes
0answers
98 views

One interface for multiple CRUD resources

I asked about an abstraction layer for accessing files (link) a couple of days ago (I decided to not call it a follow-up anymore as there are too many changes). I tried to incorporate many of the ...
6
votes
0answers
56 views

Wrapper for Google_Service_Calendar as a Symfony service

My app interacts with Google Calendar. This Service wraps Google_Service_Calendar: ...

1
2 3 4 5 6