Tagged Questions

DI, dependency-injection, is a design pattern where dependencies (instances of objects, properties) of a component are set through the constructor(s), methods or fields (properties)

learn more… | top users | synonyms

0
votes
0answers
113 views

Customizing configuration for PHP will Laravel 4 IoC be useful?

This topic has been discussed in this post: Customizing configuration with Dependency Injection However - I couldn't find one for PHP syntax and since one of the answers was to use a specific ASP.net ...
74
votes
7answers
5k views

Understanding dependency injection

I'm reading about dependency injection (DI). To me, it is a very complicated thing to do, as I was reading it was referencing inversion of control (IoC) as well and such I felt I was going to be in ...
1
vote
0answers
133 views

Manual dependency injection or abstract factory

We're starting to use dependency injection in a fairly large, interactive program. It's early yet, but I have a feeling that the majority of the objects being injected are going to want runtime data ...
4
votes
2answers
280 views

How to decouple simple factory and default implementation?

I have a simple factory class (FileResources) with static factory methods providing a default implementation (DefaultFileResource). public final class FileResources { private FileResources() {} ...
9
votes
3answers
3k views

Which classes should be autowired by Spring (when to use dependency injection)?

I have been using Dependency Injection in Spring for some time now, and I understand how it works and what are some pros and cons of using it. However, when I'm creating a new class I often wonder - ...
1
vote
2answers
106 views

Application settings via constructor injection or ambient context

I am developing an application containing a class which loads application settings from a configuration file. Settings class: public sealed class MyAppSettings : IMyAppSettings { private ...
1
vote
3answers
172 views

Should I consider loosely-coupling for class methods as well? [duplicate]

I'm a fan of Dependency Injection, however I don't know how much both public and private methods inside a class should be loosely-coupled. Just to picture it better, when I have both projectId and ...
3
votes
2answers
365 views

Help With Dependency Injection

I am still very confused as to why and when to use Dependency Injection. If anyone could explain maybe using the below example that would be great, any other explanations would be appreciated. Lets ...
0
votes
0answers
201 views

Should you implement a repository pattern with an MVVM javascript framework?

When coding a MVVM pattern I use Dependency Injection (DI) and try and code against interfaces. One of the common patterns is a Repository pattern, so I can swap my data storage provider. If I'm ...
0
votes
1answer
204 views

Practical Use of Depency Injection (IoC) Container

I am creating a MVC-ish framework in PHP. I am trying to implement a DI Container to allow the creation of controller objects (among others). My MVC framework is pretty typical. Each module (or ...
3
votes
1answer
326 views

What is the clean way to pass my LoginContext down through the layers to the data access layer?

I have inherited an API implemented using ASP.NET WebApi 2. The actions on the controllers are all like this: public object Get(long id) { LoginContext loginDetails = GetLoginDetails(); if ...
2
votes
1answer
238 views

DI or Factory Pattern ? Both ? or a different apprach?

Lets say we have an abstract class called BaseSwitch, inherited by concrete implementations Switch A and Switch B, Each Switch representing a real-life switch (A telephony tool which among its ...
0
votes
1answer
114 views

Reducing Coupling in a Series of Tasks

I am working on some code right now that involves processing user requests. Each request requires going through an approval. When a request is made, one or more records are created on the database ...
2
votes
3answers
692 views

Should IoC container be part of portable library?

I am seeing the benefits of Portable Class Libraries for centralizing Models and ViewModels to a single code-base. Where should dependency injection management (IoC container) take place, though? My ...
3
votes
2answers
893 views

What am I missing in my (mis)understanding of IoC/DI/Castle Windsor?

Okay, so here's how I understand IoC and DI in Web API to work when using Castle Windsor. Note, though, that my confidence that I understand it as I should, though, falls somewhere between my ...
0
votes
1answer
322 views

How should dependencies be managed across a modular application?

Let's say that we have a structure like this: Application -- Modules --Module1 -- Controller -- PublicHelper --Module2 -- Controller ...
4
votes
5answers
273 views

Loose coupling and shuffling dependencies

I have a bunch of classes that look something like this: public class MyGame() { private Graphics graphics; private Player player; public MyGame() { graphics = new ...
10
votes
5answers
1k views

Can I use Dependency Injection without breaking Encapsulation?

Here is my Solution and projects: BookStore (solution) BookStore.Coupler (project) Bootstrapper.cs BookStore.Domain (project) CreateBookCommandValidator.cs CompositeValidator.cs IValidate.cs ...
1
vote
1answer
112 views

Loading data for ShoppingCart item

I'm currently trying to cover our shopping cart with unit tests. Class ShoppingCartItem has property Term. It also loads available terms for this item upon object creation. Currently this is done ...
2
votes
2answers
222 views

How to refactor out static members of basic classes

Currently I am working on C++ project, which can be classified as "legacy" project. A lot of poor written code was committed because of lack of experience and under the pressure of deadlines. When I ...
2
votes
2answers
743 views

Factory Pattern and/or Dependency Injection?

I understand the concept and can use both the Factory Pattern and Dependency Injection, however they seem a little at odds with each other conceptually. Is it a case of using one over the other? Or ...
0
votes
1answer
254 views

High Level Configuration of Constructor Injection in C++

My questions are specifically dealing with dependency injection through the constructor. I understand the pros/cons of service locator pattern, constructor/setter injection, and their flavors, however ...
1
vote
5answers
874 views

What does Dependency Injection mean by saying it can inject on runtime?

I understand that the dependency injection is something done by coding and its all done at compile time. And that Dependency injection coding is easily done now by helper tools like Ninject. However ...
0
votes
1answer
133 views

Why does the modifier access for the properties need to be public with Unity?

Why does the modifier access for the properties need to be public with Unity? I'm very interested in a detailed explanation for my question. I read about tips to do it in other ways, but not a ...
1
vote
1answer
181 views

it is a good approach to implement dependency injection in a desktop app?

Well, the thing is that I am just about to create a Desktop App (with .NET windows forms) And now I just wonder if it would be really a wise choise to use any IoC (StructureMap,Ninject,Spring .Net), ...
0
votes
2answers
563 views

Can Dependency Injection used as an alternative to Reflection for creating instances

There is a piece of .net C# code which use Reflection to create an instance using Activator.CreateInstance(). This is an old piece of code and runs on the top of Enterprise Library. Is it a better ...
0
votes
1answer
157 views

Service layer coupling

I am working on writing a service layer for an order system in php. It's the typical scenario, you have an Order that can have multiple Line Items. So lets say a request is received to store a line ...
1
vote
3answers
2k views

MVVM and service pattern

I'm building a WPF application using the MVVM pattern. Right now, my viewmodels calls the service layer to retrieve models (how is not relevant to the viewmodel) and convert them to viewmodels. I'm ...
4
votes
3answers
1k views

Dependency injection: At what point am I allowed to create a new object?

I am refactoring a PHP application, and I am trying to do has much dependency injection (DI) as possible. I feel like I've got a good grasp of how it works, and I can certainly see my classes ...
1
vote
2answers
503 views

Dependency injection with Finite State Machines and the Interface Segregation Principle

I am trying to figure out what is the best way to setup a FSM and also keep my interfaces clean and use an IOC container to use DI. Let's just visit the Head First design pattern textbook example of ...
0
votes
1answer
74 views

Inject specific classes or not

I have a TableSqlBuilder interface which has a method getCreateTableSql. This interface is used in some other class as follows: function createTable( $tableDefinition ) { $sql = ...
1
vote
1answer
173 views

The Nature of Spring [duplicate]

Is it accurate to say that dependency injection manually using java (without spring) is nothing but implementing the strategy pattern (as per this example)? Furthermore, is it correct to say that ...
-1
votes
2answers
311 views

Generics vs IoC [closed]

One of the "Service Locator" pattern drawbacks is that a caller can be misleaded about dependencies of a callee. Ok, but what if I put dependencies as generic parameters at a class level: class ...
16
votes
8answers
2k views

Is Dependency Injection worth it outside of UnitTesting

Given a constructor that will never, ever, have to use any different implementations of several objects that it initializes, is it still practical to use DI? After all, we might still want to unit ...
1
vote
2answers
164 views

MVC Models instantiation

Where should the Models be instatiated in a MVC arhitecture? I understand the preferred way would be outside controllers, in a bootstrap file and injected using a Dependecy Injection Container. But ...
0
votes
3answers
1k views

MVVM application architecture, where to put dependency injection configuration class, BusinessLayer and Common interfaces?

Planning my architecture for an MVVM application I come to this: MyApp.UI View MyApp.BusinessLayer ViewModel MyApp.DataAccessLayer RepositoryImplEF MyApp.DomainLayer DomainObject ...
2
votes
1answer
170 views

Main method templating

Now that I've gotten into a dependency injection groove, I find main methods for different applications all look basically the same. This is similar to stuff you might find on the Guice documentation, ...
0
votes
2answers
161 views

Factory for arrays of objects in python

Ok, the title might be a little misleading. I have a Window class that draws widgets inside itself in the constructor. The widgets are all of the same type. So I pass a list of dictionaries, which ...
0
votes
1answer
220 views

Architecting Domain Layer and other modules with dependency injection in mind

I am currently new to Dependency Injection pattern. I am influenced by link by Mark Seemann. I have a confusion regarding whether an interface for an agent class of some agent module should be ...
1
vote
1answer
197 views

Unused dependencies and constructor injection

I have a class that has 3 dependencies. WritabbleDBConnection, ReadOnlyDBConnection and a QueryFilter utility object. I want to do constructor Injection so my class would look something like this. ...
1
vote
2answers
523 views

Very-Loose Coupling and Dependency Injection for Database Management

I'm currently setting up a MongoDB database for a web-app. I'm running node.js and using Mongoose to help manage mapping, validation ect. I'm wondering if it's a good idea to really decouple MongoDB ...
2
votes
1answer
1k views

DI / IoC Abstract Factory Galore

Given a project architecture as follows, where each box represents an assembly (all are class libraries), and each arrow stands for a dependency: Might be worth nothing that this project is massive ...
9
votes
4answers
1k views

When to use interfaces (unit testing, IoC?)

I suspect I've made a schoolboy error here, and am looking for clarification. A lot of the classes in my solution (C#) - dare I say the majority - I've ended up writing a corresponding interface for. ...
1
vote
1answer
379 views

Configuring DI in a decoupled app

I'm reading through Mark Seeman's Dependency Injection in .NET (excellent read so far) and something is escaping me. If the application's architecture is like [DAL] => [BLL] <= [UI], with the ...
3
votes
5answers
5k views

Dependency Injection Confusion

I think I have a decent grasp of what Dependency Inversion principle (DIP) is, my confusion is more around dependency injection. My understanding is the whole point of DI is to decouple parts of an ...
1
vote
1answer
162 views

Reducing repetitive DI code

I have a method which constructs dependencies using Unity. Currently, all of the calls do pretty much the same thing: Registers 2 repository object and 2 'App Part' objects. My issue is, there's a lot ...
3
votes
0answers
864 views

Passing a Context around with dependency injection

In the project I'm working on, I'm using Guice and trying to do as much as possible with Dependency Injection. However, there's one little snag; many of my objects rely on an object Context. This is ...
1
vote
1answer
465 views

DB connection Dependency Injection and static creator methods

I often use static "factory" methods to create objects from database. class Job { protected $objDb; public function __construct($objDb) { $this->objDb = $objDb; } public static function ...
4
votes
4answers
675 views

Pattern to use for different Stages in a software

I am developing a software for a laboratory to test some devices. To test each device there are multi subtests which should be done to reach to the final result.To perform a complete test, the ...
8
votes
4answers
838 views

How is dependency injection not just moving the complexity into a separate class?

I've been looking into using the Typhoon framework for dependency injection this week. I get that separating the construction of objects is beneficial for replacing arbitrary components with mocks ...