dependency-injection

How should I unit test sending email from a controller?

I'm getting started with unit testing and trying to do some TDD. I've read a fair bit about the subject and written a few tests. I just want to know if the following is the right approach. I want to add the usual "contact us" facility on my web site. You know the thing, the user fills out a form with their email address, enters a brief...

Picking Up Repositories With Structuremap

I am not sure how to use StructureMap to scan for all repositories in a particular namespace. Most repositories take the form: namespace CPOP.Infrastructure.Repositories { public class PatientRepository : LinqRepository<Patient>, IPatientRepository { } } namespace CPOP.Infrastructure.Repositories { public class LinqRepo...

What happens if a bean attempts to load the Spring application context in its constructor?

Given the following Spring application context and class A, what happens when you run class A? applicationContext.xml (in classpath): <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframew...

Dependency Injection and decoupling of software layers

I am trying to implement Dependency Injection to make my app tester friendly. I have a rather basic doubt. Data layer uses SqlConnection object to connect to a SQL server database. SqlConnection object is a dependency for data access layer. In accordance with the laws of dependency injection, we must not new() dependent objects, but ra...

Detecting type of webservice in httpmodule

Hi, Is there any way to detect the type of a webservice inside a httpmodule? The reason for this is that I want to do some property injection to the webservice before it's processed. I found this: http://social.msdn.microsoft.com/Forums/en/asmxandxml/thread/0e848eee-d353-4e67-b47f-89fddb600009 but that is one h..l of an ugly solution....

Should I create an interface for each Model?

Hey everyone I'm just getting started with Dependency Injection (DI) using Ninject and am working through my controllers looking to decouple them from my models a bit more. At the moment, inside of my controllers I am creating an instance of some given model e.g: var activitiesModel = new ActivitiesModel(); For each of my models tha...

Injecting a dependancy into a base class

Hey everyone, I'm on a roll today with questions. I'm starting out with Dependency Injection and am having some trouble injecting a dependency into a base class. I have a BaseController controller which my other controllers inherit from. Inside of this base controller I do a number of checks such as determining if the user has the rig...

Using MEF, inject into an Import class

I have a logger interface that I inject into many different classes, can I inject that class in say a repository class, which is also an Import class which is injected into other classes? Hope that makes sense, I'm a little confused by it myself. Thx ...

Unity and Object Creation

I am using unity as my IoC container. I am trying to implement a type of IProviderRepository. The concrete implementation has a constructor that accepts a type of IRepository. When I remove the constructor parameter from the concrete implementation everything works fine. I am sure the container is wired correctly. When I try to crea...

Getting an argument list for a class method

What I'd like is for this class class Car { public function __construct(Engine $engine, Make $make, Model $model) { // stuff } } Get an array that has the types needed to construct this car (Engine, Make, Model) in the order they are needed for the constructor. I'm using this for a Dependency Injection-esque thin...

Where (layer) should DI be used?

Is there any layer where it is bad practice to use DI? In a previous question a user mentioned that DI should only be used in the UI layer. ...

Avoiding dependency carrying

When coding, I often come across the following pattern: -A method calls another method (Fine), but the method being called/callee takes parameters, so in the wrapping method, I pass in parameters. Problem is, this dependency carrying can go on and on. How could I avoid this (any sample code appreciated)? Thanks ...

Inject generic parameters with structuremap 2.6

I need to inject generic repositories (IRepository) into my classes' constructors but I dont know how to do it with the new DSL in structuremap 2.6, does anyone know how? ...

hosting simple python scripts in a container to handle concurrency, configuration, caching, etc.

My first real-world Python project is to write a simple framework (or re-use/adapt an existing one) which can wrap small python scripts (which are used to gather custom data for a monitoring tool) with a "container" to handle boilerplate tasks like: fetching a script's configuration from a file (and keeping that info up to date if the ...

Is dependency injection only for service type objects and singletons? (and NOT for gui?)

I'm currently experimenting with the Google's guice inversion of control container. I previously had singletons for just about any service (database, active directory) my application used. Now I refactored the code: all the dependencies are given as parameters to constructors. So far, so good. Now the hardest part is with the graphical u...

Inject different repository depending on a querystring / derive controller and inject the repository depending on the controller type / ASP.NET MVC

I have a search form that can search in different provider. I started out by having a base controller public SearchController : Controller { protected readonly ISearchService _searchService public SearchController(ISearchService searchService) { _searchService= searchService; } public ActionResult Search(....

How to inject beans from external libs with CDI?

How can I use JSR-299 CDI to inject (not annotated) beans from external libraries? Examples: Interface X and its implementations come from a third party lib. How can I decide which implementation to use? class A { @Inject private X x; } What if I had several classes using the X interface but different implementations? cl...

How to integrate Guice 2 into Wicket?

I want to use Guice 2 with Wicket 1.4. There is a "wicket-guice" package, which uses Guice 1. Can someone give me an example how to configure Wicket to use Guice 2 for injection (with Maven). As you can see blow, I've found a solution, but I wonder, if it would be better to use Guice Servlets and register the whole Wicket Application as...

JSR-330 support in Guice

The SVN version of Guice supports JSR-330 annotations ("JSR-330 Integration - This documents an experimental, unreleased feature available in Guice SVN only"). Google gives the advise: "For now, stick with Guice's annotations and Provider interface." Guice 2 is a year old now and I wonder if there will be JSR-330 support in the near futu...

Dependency Injection, IoC and Mocking finally explained in a simple and understandable way!

I've been banging my head against the wall trying to understand these concepts for a week now. I was really surprised when I came across with a very understandable and simple explanations of these concepts in the ASP.NET MVC NerdDinner application tutorial. I suggest this to anyone struggling to have that 'aha' moment. http://nerddinner...