dependency-injection

Strategy Pattern and Dependency Injection using Unity

I am finally getting my feet wet with Dependency Injection (long overdue); I got started playing with Unity and run into an issue with the strategy pattern. I can use the container to return to me specific implementations of a strategy based on a name, but what I don't see is how I am supposed to get the right strategy in the context. Le...

Dependency Injection: How to maintain multiple configurations?

Hi StackOverflow, Lets assume we've build a system with a DI framework which is working quite fine. This system currently uses JMS to "talk" with other systems not maintained by us. The majority of our customers like the JMS approach and uses it according to our specification. The component which does all the messaging is injected with ...

Dependency Injection: Jetty 7

Hi StackOverflow! My application requires several interface implementations which require a Jetty server to do their job. This is, however, not necessarily the case in every implementations of those interfaces so the Jetty server is only a dependency. Since it would be a huge amount of pain to wrap the entire jetty server with all its ...

Abstractions should not depend upon details. Details should depend upon abstractions ?

In past couple of days, I have read about quite a lot about dependency injection/inversion of control/inversion of dependency. I think that, now my understanding of the concept is much better. But I still don't get the following from wikipedia: A. High-level modules should not depend on low-level modules. Both should depend on ab...

ASP.NET MVP Injecting Service Dependency

I have an ASP.NET page that implements my view and creates the presenter in the page constuctor. Phil Haack's post providing was used as the starting point, and I'll just the examples from the post to illustrate the question. public partial class _Default : System.Web.UI.Page, IPostEditView { PostEditController controller; pub...

Dependency Injection - is this how it's meant to look?

Our project is using constructor-based Dependency Injection (we're using Unity as our container) and we have a number of constructors which have acquired a large number of parameters. For example: public FooRequestService( ITransactionDataBuilder transactionDataBuilder, IMapper<SaveFooRequest, FooRequestMessage> sav...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered is in naming services Example SomthingGatewayService.groovy can't be initialized in both these ways - SomthingGatewayService somtinggatew...

Appropriate Situation for Using IoC Container?

Let's say I have a common WCF service and console app project that do not change across client specific deployments. I have some interfaces in the common projects that are implemented by specific client code. The client code obviously changes from client to client. I'm thinking this would be an appropriate use for an IoC container. In my...

Dependency Injection - Who owns the Interface?

Assuming I want to use a dependency injection framework in an AOP approach, with the goal of producing code modules. What's the best practice for the ownership of the shared interfaces? By ownership I mean the body of code that needs to be referenced in order to use the interface. My first guess is that in AOP you would define a class...

Getting Unity to Resolve views in XAML

I'm starting out with MVVM, and I'm starting to understand things. I'm currently experimenting with the Cinch framework, though I'm not committed to it as of yet. I was injecting the ViewModels into the Views using by having a reference to the ViewModel in the codebehind of the view, with the property having a [Dependency] on it, and in ...

IOC with multiple databases that use same interface (StructureMap or any other DI Framework)

We've been experimenting with StructureMap, and I'm having trouble grasping how to handle situations where a single interface has multiple implementations. The code below shows an example where we have two databases that are both accessible from a single service. public class SomeController : Controller { private ISomeService _servi...

Dependency Inject Sql Connection?

Firstly, I'm starting to use StructureMap, but an example in any DI framework will do. I have a class as so, public class GeoData { public List<Country> GetCountries() { IDbConnection con = new SqlConnection(ConfigurationManager.ConnectionString["GeoDataConnection"]) //Sql stuff to return countries from a database...

Unity constructors

I have setup unity in my project and it is working for objects that don't have constructor injection implemented on them. The issue is now I do have an object which requires a custom object as a constructor argument. I have set up the config below, and this errors telling me that "TypeConverter cannot convert from System.String" <unit...

Unity: passing an instance of the model state to the injected dependency

Hi, I'm refactoring the controllers in a .net MVC app so I can inject the dependencies using the unity container. There's this service that needs a reference to the controller's modelstate so I'm hitting a roadblock here. Is it possible to get a reference to the controllers's modelstate at the time of the injection? I'm currently registe...

Where should I store a reference to my DI container?

I'm wondering how I should store/reference my dependency injection container(s). Is it alright to have a container be a static property on a static class? Or should I have the container be an instance variable on the application? I'm wondering what the pros and cons of each option are, and what is the best practice for this in web, mvc, ...

Castle Windsor: Problem with Multiple Constructors

Hello stackoverflow! Long-time reader first time writer here. I am currently undertaking a conversion from to the use of Ninject to the current release of Castle Windsor for a simple C# .NET application. For the most part, the conversion has gone well and the implementation of the containers has executed flawlessly. I am however hav...

array dependency injection in spring?

Hi, is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @Autowired for this: public class Foo{ @Autowired private IDataCollector[] collectors; } Is this supported, would this require h...

Using the Ninject kernel as a Unit of Work object factory.

So I'm starting to use Ninject for dependency injection and I'm wondering what people think of using a kernel as an object factory for Unit of Work type objects like Linq2Sql Datacontexts. I would just inject them like normal dependencies, but this introduces some object lifetime issues I'd like to avoid. DataContexts are different tha...

IoC Containers and Domain Driven Design

I've been searching for guidance for using IoC containers in domain driven design. Evan's book unfortunately doesn't touch on the subject. The only substantial guidelines I could find on the internet is here. Many of Malovic's points are common sense but I'm concerned about a few of them. He suggests that IoC container's should be reser...

Dependency injection: injecting user control in aspx page

I need to build a 'customizable' asp.net web application (not asp.net mvc). I was thinking to use an IoC container to inject user control into aspx pages. Has anybody ever tried that ? In brief here is how I think this can be achieved: I use Scott Guthrie's method to build a reusable 'user control library' (see his article "Creating...