dependency-injection

Dependency injection in C++

This is also a question that I asked in a comment in one of Miško Hevery's google talks that was dealing with dependency injection but it got buried in the comments. I wonder how can the factory / builder step of wiring the dependencies together can work in C++. I.e. we have a class A that depends on B. The builder will allocate B in t...

Dependency Injection while dynamic assembly loading

i have a winforms applicatoin that has a lot of implementations of IOrderDataLoader. Other teams are starting to build their own new implementations of IOrderDataLoader. So we switched our app to look in a directories of Dlls and load all classes that implement IOrderDataLoader using reflection. This way other groups can deploy their ...

dependency injection alternatives

I am looking at depency injection, I can see the benefits but I am having problems with the syntax it creates. I have this example public class BusinessProducts { IDataContext _dx; BusinessProducts(IDataContext dx) { _dx = dx; } public List<Product> GetProducts() { return dx.GetProducts(); } } The prob...

How do I make sure that there is one NHibernate ISession per request using Autofac?

I have the following code in an Autofac Module that is used in my Application_Start method: builder.Register(c => new Configuration().Configure().BuildSessionFactory()) .SingletonScoped(); builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()) .HttpRequestScoped(); builder.Register<NHibernateSomethingRepository>().As...

Using mock objects outside of testing, bad practice?

I'm working on a project where there is a lot of external service messaging. A good way to describe it in only a slightly "hyperbolas" way would be an application where the system has to send messages to the Flicker API, the Facebook API, and the Netflix API. To support disconnected scenarios, logging concerns, developer usability, conf...

Pattern suggestions needed (Hibernate + Guice)

Hi, all, I'm looking for suggestions on how to inject runtime dependencies into JPA entities retrieved from Hibernate. My problem is essentially this: I have a number of different subclasses of a Transaction object. Each Transaction subclass has different behavior when it is executed, and requires a different set of dependencies from t...

How do you implement constructor injection in a factory?

When you're using a factory pattern, how do you inject dependencies into constructors at runtime? I'm building Foos with different formats - boolean, array, freetext, matrix, etc. That format list will grow as we find different uses for Foo. Here's my basic core domain: public interface IFoo { FooFormat Format { get; } } public ...

What assemblies do I need to start using Castle Windsor in my application?

I've got a pretty basic question about how to start using Castle Windsor. I've read up on IOC/DI and would like to try Castle Windsor in an existing solution. I typically like to put any external assemblies in a Lib folder within the solution's folder tree so that the references are relative (I believe this is best practice). Which ...

Giving PHP object-type arguments a default value

Hello, I'm writing a PHP application with testability in mind, so my classes always ask in their constructors for the "collaborator objects" they depend on, in respect to the Dependency Injection pattern. That way, I'm able to pass in mocks or test implementations in my unit tests. What I want to achieve though, is to be able to insta...

Can WCF Service have constructors?

When I new a WCF service in my solution, can I do the following, have a constructor with parameter to pass in? If yes, how, when and where does the runtime fill in my required IBusinessLogic object? [ServiceContract] public interface IServiceContract { [OperationContract] ... } public class MyService : IServiceContract { I...

Which patterns for loose coupling do you use most?

Lately I have seen a lot of blog posts concerning how to build loosely coupled applications. Which patterns do you use most when creating loosely coupled applications? Dependency Injection? Inversion of Control? ...

DI/IoC, NHibernate and help in getting them to work together.

I'm trying to get my head around DI/IoC, NHibernate and getting them to work nicely together for an application that i'm developing. I'm quite new to both NHibernate and DI/IoC so not quite sure whether what i'm doing is the sensible way to be going about it. This is the scenario: The application provides users with the ability to calc...

Castle Windsor Are There Any Downsides?

I have been looking into the castle project and specifically windsor. I have been so impressed with what is possible with this technology and the benefits of having a such a loosely coupled system are definitely apparent. The only thing i am unsure of is if using this method has any downsides, specifically in asp.net?? for example perfor...

Castle Windsor to Unity - can you auto-configure in Unity the same way you can in CW?

Hello, I don't know if this is too specific a question, if that is possible, but I'm having to port an app that uses Castle Windsor to Unity so that there isn't a reliance on non-microsoft approved libraries. I know I know but what are you going to do. Anyway I've managed it but I'm not happy with what I've got. In Windsor I had this: ...

StructureMap with WCF?

Anyone had any luck integrating StructureMap (DI Framework) with WCF? I can return the default instance in the constructor of my WCF service like this, but obviously it is not ideal. public MemberService() { this.memberRepository = StructureMap.ObjectFactory.GetInstance<IMemberRepository>(); } I have seen this (http://www.lostec...

Linq2Sql, OOP, DependencyInjection problem

I'm still struggling a bit with OOP concepts and dependency injection so bear with me. I have generated my Linq2Sql model with a User table and now I would like to be able to send a confirmation email to this user so I created a partial class file for my User object and I felt it was natural to add a SendConfirmationEmail() method to th...

Windows Workflow Foundation or IoC container + Dependency Injection?

I am trying to figure out the internals of the windows workflow foundation. So, we have some software components and we intertwine them in the form of a workflow be it a condition based sequential workflow or a state machine workflow. Now, I am thinking (I may be wrong here) that doesnt the same apply to IoC + Dependency Injection (via U...

Choosing a .Net Inversion of Control container for first attempt at Dependency Injection

Which IoC container is the easiest to get started with. This probably equates to which ones have the friendliest documentation. Not too worried about number of features. ...

How to avoid duplicate code when using mocks in unittests

I am using dependency injection to supply mocks for code outside of my class under test. I find myself writing alot of the same code over and over as I need to mock out AuthProvider, ConfigurationManager, etc. which are used in the method I want to test. The method contains branches (if-then-else) and therefore I have multiple tests in p...

Export a Unity container information to xml configuration

In Microsoft Unity you can configure a container from an existing XML configuration but is there a way to do the opposite? From an initialized container export the corresponding XML configuration? ...