Skip to main content

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
43 votes
4 answers
6k 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 ...
Mathieu Guindon's user avatar
31 votes
6 answers
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 without ...
Simsons's user avatar
  • 723
23 votes
2 answers
21k 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 ...
Christian Gollhardt's user avatar
20 votes
1 answer
34k 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 ...
mitomed's user avatar
  • 539
20 votes
1 answer
17k 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....
Snæbjørn's user avatar
19 votes
2 answers
4k 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 ...
Mathieu Guindon's user avatar
18 votes
2 answers
4k 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 for ...
AHeyne's user avatar
  • 428
15 votes
2 answers
39k 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 ...
Guillermo Gomez's user avatar
15 votes
1 answer
2k views

Flask view dependency injection

I've been into trying to have an as simple as possible dependency container in Python and with your help managed to conceive TinyDIC, many thanks. Now, I use Flask for my apps, and from by background ...
user avatar
14 votes
4 answers
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: ...
Simsons's user avatar
  • 723
14 votes
2 answers
2k 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 ...
Mathieu Guindon's user avatar
13 votes
2 answers
11k 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 ...
1110's user avatar
  • 217
13 votes
1 answer
7k 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 ...
Akim's user avatar
  • 475
13 votes
1 answer
11k 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: ...
eddy's user avatar
  • 231
12 votes
4 answers
618 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 ...
Mathieu Guindon's user avatar
12 votes
2 answers
343 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: <...
Big McLargeHuge's user avatar
11 votes
2 answers
2k 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 ...
Mathieu Guindon's user avatar
11 votes
1 answer
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 ...
Patrick Magee's user avatar
11 votes
1 answer
282 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 ...
Mathieu Guindon's user avatar
11 votes
1 answer
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 ...
Mathieu Guindon's user avatar
10 votes
2 answers
3k 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 ...
Mathieu Guindon's user avatar
10 votes
2 answers
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 ...
321X's user avatar
  • 378
10 votes
1 answer
4k 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 ...
t3chb0t's user avatar
  • 44.3k
10 votes
2 answers
4k 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: ...
Mathias Lykkegaard Lorenzen's user avatar
10 votes
1 answer
822 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: ...
Sean Anderson's user avatar
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....
Dan Oberlam's user avatar
  • 7,814
9 votes
3 answers
2k 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: ...
Jeff's user avatar
  • 223
8 votes
4 answers
790 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: ...
Jhe's user avatar
  • 131
8 votes
2 answers
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 ...
user886596's user avatar
8 votes
3 answers
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 ...
Null Reference's user avatar
8 votes
3 answers
1k 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 ...
t3chb0t's user avatar
  • 44.3k
8 votes
1 answer
387 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 ...
bcmcfc's user avatar
  • 183
8 votes
1 answer
422 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) ...
Summer's user avatar
  • 2,330
8 votes
1 answer
6k 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 ...
cjones26's user avatar
  • 181
8 votes
1 answer
125 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 ...
Mathieu Guindon's user avatar
7 votes
2 answers
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 ...
janhartmann's user avatar
7 votes
2 answers
29k views

Adding extension methods to IServiceCollection in ASP.NET Core

I have the following extension method to add themes support to my application: ...
nfplee's user avatar
  • 131
7 votes
2 answers
13k 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 ...
atamanroman's user avatar
7 votes
1 answer
8k views

Full integration test for a Console application

I'm sill experimenting with different design patterns for full integration tests for Console applications (and later also Windows Services) and I wasn't quite happy with the result of the refactoring ...
t3chb0t's user avatar
  • 44.3k
7 votes
2 answers
1k 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 ...
t3chb0t's user avatar
  • 44.3k
7 votes
1 answer
122 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 ...
CodeYogi's user avatar
  • 5,107
7 votes
2 answers
22k 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 ...
hyperN's user avatar
  • 231
7 votes
1 answer
3k views

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

I configure asp.net identity using Simple Injector ...
Rod's user avatar
  • 131
6 votes
2 answers
738 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 ...
Rémi A's user avatar
  • 61
6 votes
1 answer
25k views

Dependency Injection into an Abstract Class

Me and another developer have recently forked and taken over an abandoned, open-source project. I have also been reading articles and watching videos by Misko Hevery. When I was reading through the ...
Nikolaii99's user avatar
6 votes
1 answer
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 ...
C Ivemy's user avatar
  • 245
6 votes
2 answers
2k views

"CommandBus" with Handlers & Observers

I'm looking for a very simple (at first sight) CommandBus, which will handle some ICommand publication. The ...
jbuiss0n's user avatar
  • 161
6 votes
1 answer
334 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 ...
TeaDrivenDev's user avatar
5 votes
2 answers
223 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 ...
A.B. Carroll's user avatar
5 votes
1 answer
3k 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 ...
MoonKnight's user avatar

1
2 3 4 5 6