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
vote
1answer
38 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
77 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
62 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
100 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
25 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
145 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
49 views

Using functional interface arguments in methods of services injected via Spring

Here is the working code for my Spring service: ...
1
vote
0answers
38 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 ...
0
votes
0answers
29 views

Business logic refactoring needed

I am using asp.net web API and EF code first. I am querying the database based on values inside of the request object (initiate). If there are results, I am updating the database. Then I am querying ...
0
votes
2answers
53 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
135 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
86 views
2
votes
0answers
78 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 ...
1
vote
0answers
235 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 ...
0
votes
0answers
37 views

Class to create and send a PDF form with attached documents

I'm currently working on building a class to create a PDF form application with attached documents and sending that file to an endpoint in Box Api. I have found extremely difficult managing ...
5
votes
0answers
133 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 ...
3
votes
0answers
68 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 ...
8
votes
3answers
319 views

Multiple file access abstractions

When using dependency injection for nearly everything it's good to have some file access abstraction. I find the idea of ASP.NET Core FileProvider nice but not sufficient for my needs so inspired by ...
3
votes
0answers
60 views

Override prototype inside of constructor of ES6 class for dependency injection

We implemented a small dependency injection mechanism which we use in our project. Now after 2 years of developing our project we need our classes to know who instantiated them via dependency ...
3
votes
1answer
80 views

Instantiating View Models using a static factory

I am building an e-commerce website. I have an application layer service called SearchService. SearchService receives a search ...
2
votes
0answers
101 views

GUI to control a NZXT cooling and lighting system

I am working since a couple of weeks on my first Python application and I would love to have a review of the code I wrote so far. The app has the purpose of controlling the cooling and lighting of an ...
1
vote
0answers
57 views

Dependency resolver in PHP

I wrote a simple Dependency Resolver in PHP that I'm hoping to get some input on. The main problem that gave me some trouble was when it had to resolve typed arguments ( like type hinting a ...
2
votes
0answers
56 views

Dependency Inversion in constructor

Currently I'm learning OOP and meanwhile I'm trying to keep the SOLID principles. Is it right to inject dependency (GenName - generate file name) on File ...
1
vote
0answers
170 views

Xamarin Forms with Ninject navigation service

I am new to Xamarin Forms and I have been searching online finding ways to set up navigation in a MVVM fashion. In particular I am designing around a concept I found here. However, I am using Ninject ...
1
vote
2answers
580 views

Creating an instance of an unit of work (NHibernate)

I'm trying to figure out how to create a NHibernate UnitOfWork using .NET Core Dependency Injection. I was just hard-coding the ...
0
votes
1answer
33 views

Manager that collects and handles multiple tasks that run on events like window.scroll, window.resize etc

I'm working on a website where different things can occur on resize and scroll events. I only want one event handler that comes ...
3
votes
1answer
222 views

Socket server in c#

I'm writing a socket server for a project I am working on. I'm used to working in .NET FW, but I'm attempting to write this using .NET standard/core. Particularly, I am concerned about managing ...
0
votes
0answers
60 views

Inject settings as a dependency, and serve them using a Web API

I used an opportunity to learn about Dependency Injection and DDD, therefore, althought any feedback is welcome, I am interested in feedback about those software design principles. I have a small ...
1
vote
2answers
163 views

Mandatory dependency in a class

I have a class with some mandatory properties which I set via constructor, like this (properties omitted for sake of simplicity): ...
3
votes
1answer
366 views

API client, using an injectable helper to aid testing

description write a api client that fetch items from remote service I have separated Service{} class's helper methods into another class ...
6
votes
1answer
220 views

The Last Lost Bubble Shooter - a Board game for children

In this game the pieces are trains and you move forward on the track (never backwards) in search of your goal. The players move based on a combination of resources (Soap and Water to make Bubbles) ...
2
votes
0answers
216 views

Show mobile SoundCloud player in WebView

Demo for a SoundCloud player in WebView for specific song or artist stream as a workaround because SoundCloud is not accepting API key request anymore. SoundCloudWebView: ...
2
votes
0answers
86 views

Centralized static factory methods with dependency injection

I am trying to make a small e-commerce backend in php. I centralized all the static factory methods in a class called EntityFactory. The main reason for that was to ...
0
votes
0answers
416 views

Dependency Injection and Service Locator/DI Container

I have implemented clean architecture for my app, and I have a few questions. Typically, pure DI is argued for over a Service Locator pattern, because it is very explicit and more testable. However, ...
2
votes
1answer
3k views

Injecting a DbContext with an async constructor dependency

The goal is to construct a DbContext with a connection that uses an access token. The access token is acquired with ADAL (Active Directory Authentication Library). ...
2
votes
1answer
213 views

Laravel Dependency Injection : Perfomace Issue And Architecture Style

I have a TransportationController which uses six repositories. The repositories are injected to the controller via constructor and method. TransportationController.php ...
4
votes
0answers
2k views

Using IServiceScopeFactory without implementing the Service Locator Pattern

I want to use IServiceScopeFactory in a way, which is not the Service Locator anti-pattern. Therefore I thought about making a generic one, which supports ...
7
votes
2answers
8k views

Adding extension methods to IServiceCollection in ASP.NET Core

I have the following extension method to add themes support to my application: ...
1
vote
0answers
60 views

Dependency injection for a bus with a stop-request display application

I have been told that my implementation below doesn't need dependency injection, however Jeffrey Way uses DI in two similar examples in this tutorial: https://laracasts.com/lessons/tell-dont-ask and ...
1
vote
1answer
54 views

Separating logic per class and being able to use dependency injection

I use Laravel, but hopefully this doesn't matter. I have a user and user's state. Say, simple integer or a string. I want to run some logic depending on user state in my service class. So, the first ...
2
votes
0answers
97 views

Find a (nearly) optimal route among several locations that can be found by Google Maps

The README should give you all of the information you need for a comprehensive review, and if it doesn't then please say so. If you would like to contribute a review but do not have time or desire to ...
6
votes
1answer
1k views

Stopwatch dependency for unit-testing

My AsyncDetector is internally using a Stopwatch to calculate time intervals. Because of this hardcoded dependency I am not able ...
4
votes
2answers
176 views

Using dependency injection for Node payment system

I would like some feedback on my code. I am currently building a payments solution in a serverless lambda project. This what I came up with (very basic code at the moment): ...
1
vote
2answers
2k views

Activator with simple dependency injection

In one of my projects I needed a simple dependency incjection activator so I've built one. It performs only type/inheritance matching because I'm not creating a second Autofac and I think I won't need ...
0
votes
1answer
81 views

Different implementation of an Interface along with additional parameters

I am designing an interface for 2 distinct implementations as follows: Perform operations without client credentials ( for my local applications) Perform operations using security token. (for web ...
2
votes
2answers
4k views

Using Autofac to do DI in a static factory method

I'm using Autofac to create one of my classes inside of a static factory method Create. This code is working and I haven't noticed any side effects yet. Admittedly, ...
4
votes
0answers
3k views

Logging in ASP.Net MVC project

I want to implement a Logger and use Serilog as Provider. My Project is ASP.NET MVC Framework (not core). Initially I tried to replicate ASP.Net Core Logging framework. I created a ...
12
votes
4answers
363 views

Constructor-injecting a truckload of commands

There's a problem in Rubberduck that we haven't neatly solved yet, and as we're exploring alternative approaches I figured I'd ask the CR community and see what our C# experts think. Here's the ...
0
votes
1answer
153 views

Dagger 2 test application

I have a complicated Dagger 2 use case on Android, where I have a lot of dependencies, but some of them are really slow to construct. Like 2-3 seconds slow. My solution was to create an RX ...
0
votes
1answer
113 views

Controller with too many parameters with DI [closed]

Is there a way to reduce the number of parameters of this constructor? All the services must be used in this Controller. The majority of them are used more than 2 times(some of them >10), with the ...