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
40
votes
4answers
4k views

Rock-Paper-Scissors-Lizard-Spock Challenge

"Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitate lizard, lizard eats paper, paper ...
28
votes
6answers
3k views

Extensible code to support different HR rules

Recently, I got challenged to code with following bullet points: Extensible code to support different annual leave rules for HR departments Maintainable code to add/change the existing rules ...
19
votes
1answer
32k views

Autofac DI container in console app

Just used DI containers in MVC projects, via constructor injection, and I'd need to now inject a service into a console app. I'm using Autofac so I followed what I found here. The code would be ...
19
votes
1answer
15k views

Injecting AutoMapper profiles

I'd like to know if I'm doing profile configuration in the wrong place or in the wrong way. I'm following the Onion Architecture, so that restricts the direction of my dependencies towards the center....
15
votes
2answers
3k views

Down the rabbit hole with MVP

Following-up on this post where I implemented a Repository Pattern in vba to abstract ADODB and enable testing my Excel app without hitting a database backend; curious about how far vba would let me ...
15
votes
2answers
33k views

Unit of work + repository + service layer with dependency injection

I am designing a web application and a windows service and want to use the unit of work + repository layer in conjunction with a service layer, and I am having some trouble putting it all together so ...
15
votes
2answers
2k views

Using events together with interfaces in VBA

Introduction Because of the limitation of VBA in using events in interfaces I was searching for a kind of workaround. For sure I also read this which also provides an approach, but I was searching ...
14
votes
4answers
2k views

Making a web service call based on a type of request

I have my code which makes a web service call based on a type of request: ...
14
votes
2answers
992 views

YARPI: Yet Another Repository Pattern Implementation

Following-up on this post, I wanted to be able to put a copy of that Excel workbook on a USB key and take it home to keep working on the code a bit (there's more than just one or two tables to ...
13
votes
2answers
10k views

Do I need ninject when implementing DAL with generic repository and unit of work?

I am implementing generic repository and unit of work for the first time. I would be glad if someone can correct me if I am doing something wrong here. This is how I communicate with my DAL from ...
12
votes
4answers
367 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 ...
12
votes
1answer
6k views

Inject dependency into PostSharp aspect

I have designed couple of aspects using PostSharp for different projects, but there is a design flaw in many of them: dependency management. This is a question about injection of dependencies into ...
12
votes
2answers
305 views

Setting up keyboard bindings using JSON (no reflection!)

I got a lot of good feedback on my other question. So I will take another swing at it, post my revisions, and hopefully get some more. First, the configuration hasn't changed. Here's the JSON file: <...
11
votes
2answers
1k views

Rock-Paper-Scissors-Lizard-Spock Challenge, take 2

This post is following-up on Rock-Paper-Scissors-Lizard-Spock Challenge I had a gut feeling that I was somehow abusing IComparable<T>, @svick's answer ...
11
votes
1answer
2k views

How can I solve my constructor injection code architecture?

The current code solves the issue I had when trying to use property injection. Problem: Every module must use constructor injection because of a circular reference that occurs when not using ...
11
votes
1answer
269 views

Having trouble with KISSing

There's a bit of a weird piece in my API that I'm not too happy about, but I can't seem to see any other way of going about. It involves a IFunctionalityFactory ...
11
votes
1answer
1k views

IoC Registration: Convention over Configuration

The rubberduck project has reached a turning point. The core features are implemented (except the SmartIndenter embedding - we're keeping that for 2.0), the next few releases will probably just build ...
11
votes
1answer
7k views

Unit of Work (UoW) pattern with ADO.NET

I'm trying to implement the UoW pattern using ADO.NET and this is what I've achieved so far: The IUnitOfWork Interface: ...
10
votes
2answers
2k views

Will this Circuit Breaker catch fire?

I was going to post this code as an answer to a recent question, but I wrote this code a little while ago (like, a year ago; if I recall correctly I wrote this after reading this article) and I'd like ...
10
votes
2answers
2k views

Send message with SignalR to client(s) from injected (IoC) method

I am new with SignalR and still a newbie with IoC Container SimpleInjector and I am ...
10
votes
1answer
741 views

Should a Factory ever be generated per request?

I'm working with AutoFac to do some DI. I think I've got a decent grip on things, but just ran into a question I had with my code and thought I'd check: ...
9
votes
3answers
1k views

Why would I want to always have to explicitly call a “base” method if I just want to use base functionality?

I recently worked with an architect who structured his base class like this: ...
8
votes
4answers
735 views

Finding the lowest and highest values in an array… with “Poor Man's DI”

I am practicing my object oriented knowledge, so I created a very simple program that determines which is the lowest and highest number inside array. This is my main method: ...
8
votes
3answers
2k views

Refactoring method to make it unit testing friendly

I have a completed application which I'm trying to write unit tests for (Yeah I know, talk about bad practices) I have the following class here ...
8
votes
3answers
369 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 ...
8
votes
2answers
2k views

Allowing query handlers to use other query handlers

I recently started looking into CQRS when using Entity Framework and the impact it has had on my systems has been overwhelming. I implemented the following patterns described in these blog posts: ...
8
votes
1answer
110 views

CommandBars, Buttons and Commands: Take 3

Following up on CommandBars, Buttons and Commands: Take 2, I've refactored quite a lot of the Rubberduck code base (like, a whole third of the entire code base has been affected), and successfully ...
7
votes
2answers
2k views

ViewModel creator design

I am trying to move some logic outside my controller for creating my view models for the view. I have a lot of queries to fire to make sure the complete view model is ready, so to keep my ...
7
votes
2answers
6k views

Spring password validator library

I recently got rejected at a job interview for submitting this: https://bitbucket.org/gnerr/password-validator The interviewer asked for a password validation library that was configurable via ...
7
votes
2answers
9k views

Adding extension methods to IServiceCollection in ASP.NET Core

I have the following extension method to add themes support to my application: ...
7
votes
1answer
370 views

Is this a sensible way of using an IoC container?

I have a Factory class for a queuing system I'm playing around with. Consuming classes only care that they get a particular interface (Job) as a result of calling the factory's load method. Some ...
7
votes
3answers
865 views

VB6/VBA Declaration (Dim) Syntax Parser

As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a vb6/vba Dim statement. Given a line of code, the ...
7
votes
2answers
657 views

Initializaing and running Console application

In most of my applications I think my core code is quite good organized and uses only dependency injection for everything. However as far as the initiailzation is concerned I find it's a huge chaos ...
7
votes
1answer
110 views

Designing a toy dependency injection library

Just for learning purpose I thought to write a simple and useful dependency injection service which would just do dependency injection but also it should expose its core too which would let the client ...
7
votes
2answers
18k views

C# - Entity Framework + Repository pattern + Unit of work pattern

After hours spent on reading various articles about correct way to implement Repository patter & UoW patters I finally think that I have managed to create (hopefully good) implementation. The ...
7
votes
1answer
5k views

AutoFac, NHibernate & ASP.NET Web API integration

I've recently been learning (and struggling with) integrating AutoFac, NHibernate & ASP.NET Web API. I have found several tutorials with code that did not work as anticipated but managed to ...
7
votes
1answer
2k views

Dependency injection with asp.net identity and property injection with dbcontext

I configure asp.net identity using Simple Injector ...
7
votes
0answers
1k views

Flask view dependency injection

so, first of all, I've been into trying to have a simple dependency container as possible in python and with your help managed to get conceive https://github.com/dareenzo/tinydic, many thanks. Now, I ...
6
votes
2answers
11k views

Spring autowiring in managed beans with support for serialization - is this safe?

Im trying to solve two problems I see with JSF2 and Spring. First @Autowired in @ManagedBean does not work Nor does ...
6
votes
2answers
466 views

Dependency problem in C#, through polymorphism, and appropriate design pattern

I'm currently working on a project which involves EntityFramework with a (very) rich model (lots of inheritance). I'm currently facing a problem, quite interesting in my opinion. My model is ...
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 ...
6
votes
1answer
243 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) ...
6
votes
1answer
766 views

Dependency Injection Provider/Container

I've been working on a class to handle dependency injection across some code akin to a micro-framework. This is also my first real dive into any sort of wrapper for dependency injection. I decided to ...
6
votes
1answer
327 views

Doubts about the quality of an API designed for use with minimal effort

I'll try to provide exactly the amount of context that is necessary to understand the construct. I built an API (well, a small part of one) that works and is kind of usable, but rather unpretty and ...
5
votes
2answers
206 views

Generic Networking Class for PHP

I am in the process of writing networking code for PHP that is meant to be used in long-running PHP processes. I realize that PHP is supposedly not well suited for long-running processes, however ...
5
votes
1answer
2k views

UnitTesting with Mocking and Dependency Injection using Ninject

I have the following scenario that I have not come across so far using Ninject. I have the following class structure (simplified for easy of reading :]). First the abstract base class for all ...
5
votes
2answers
882 views

Abstracting a Password Service

I want to use Microsoft.AspNet.Identity's PasswordHasher but I don't want to pollute my Domain layer with knowledge of it. As ...
5
votes
1answer
5k views

Looking for advice - Dependency Injection over Service Locator in Mef

I'm wondering what people think about Dependency Injection vs Service Locator patterns. Specifically I'm using Prism with MEF. I'm also using the MVVM pattern. So I have a service which I export. I ...
5
votes
2answers
2k views

Wrapping a .NET Database Connection

I have created a DatabaseConnection class as this: ...
5
votes
1answer
1k views

PHP class architecture and dependency injection

Let me start off by saying I am not new to PHP or PDO, but very new to OO PHP, and have been struggling to get a firm idea of best practices in my head regarding dependency injection and structuring ...