dependency-injection

Simplifying Testing through design considerations while utilizing dependency injection

We are a few months into a green-field project to rework the Logic and Business layers of our product. By utilizing MEF (dependency injection) we have achieved high levels of code coverage and I believe that we have a pretty solid product. As we have been working through some of the more complex logic I have found it increasingly difficu...

WCF and Unity - Dependecy Injection

I'm trying to hock up WCF with dependecy injection. All the examples that I have found is based on the assumptions that you either uses a .svc (ServiceHostFactory) service or uses app.config to configure the container. Other examples is also based on that the container is passed around to the classes. I would like a solution where the ...

Dependency injection in constructors

Hello everyone. I'm starting a new project and setting up the base to work on. A few questions have risen and I'll probably be asking quite a few in here, hopefully I'll find some answers. First step is to handle dependencies for objects. I've decided to go with the dependency injection design pattern, to which I'm somewhat new, to hand...

Graph limitations - Should I use Decorator?

I have a functional AdjacencyListGraph class that adheres to a defined interface GraphStructure. In order to layer limitations on this (eg. acyclic, non-null, unique vertex data etc.), I can see two possible routes, each making use of the GraphStructure interface: Create a single class ("ControlledGraph") that has a set of bitflags spe...

IoC / Dependency Injection - please explain code versus XML

I understand basically how IoC frameworks work, however one thing I don't quite get is how code-based config is supposed to work. With XML I understand how you could add a new assembly to a deployed application, then change the config in XML to include it. If the application is already deployed (i.e., compiled in some form) then how can ...

Why not lump all service classes into a Factory method (instead of injecting interfaces)?

We are building an ASP.NET project, and encapsulating all of our business logic in service classes. Some is in the domain objects, but generally those are rather anemic (due to the ORM we are using, that won't change). To better enable unit testing, we define interfaces for each service and utilize D.I.. E.g. here are a couple of the ...

inject different implementations by logged User Role

public class TheController : Controller { IThe the; public TheController( IThe the) { //when User.IsInRole("r1") The1 should be injected else r2 this.the = the; } } public class The1 : IThe{} public class The2 : IThe{} //anybody knows a good way of doing this ? ...

Autofac or Ninject? - which should I go for?

I'm hitting paralysis by analysis I think... Which should I go for for my first IOC container: Autofac or Ninject? (Just want an open source, nice and simple, IOC container) ...

What's the most minimal way to achieve Dependency Injection?

I've been reading about Spring and although it's claimed to be a less complex alternative to EJB, I'm having a hard time wrapping my head around it. Is there a more minimal way of achieving Dependency Injection than adopting the Spring approach? ...

Dependency Injection: What's wrong with good old-fashioned refactoring?

DI creates an extra layer of abstraction so that if your implementation class ever changes you can simply plug in a different class with the same interface. But why not simply refactor when you want to use a different implementation class? Other languages like Python and Ruby work fine this way. Why not Java? ...

StructureMap resolve dependency through injection instead of service location

In my project I register many ISerializers implementations with the assembly scanner. FWIW this is the code that registers my ISerializers Scan(scanner => { scanner.AssemblyContainingType<ISerializer>(); scanner.AddAllTypesOf<ISerializer>().NameBy(type => type.Name); scanner.WithDefaultConventions(); }); Which then correct...

In a project that uses a DI framework, should you NEVER use the 'new' operator?

I'm trying to wrap my head around Dependency Injection. One of the things I'm confused about is whether all of your object instantiation needs to be controlled by the DI framework (Spring, Guice, etc). Or, if not, how do you determine which objects are instantiated by the framework and which objects are instantiated with the new oper...

Why do people talk about DI frameworks "instantiating an object graph" rather than "instantiating objects"?

I'm reading a book about DI that always talks about DI frameworks "instantiating an object graph". Why say it this way rather than "instantiating objects"? ...

What are the best DI-IOC references for a vb.net programmer?

I code primarily in vb.net. I've been doing basic dependency injection manually and am looking to learn more about DI/IoC and maybe use a DI/IoC framework/container like Ninject. There are lots of examples and write-ups using Java and C# code. I'm looking for the best resources for vb.net programmers. Likewise, is there a particular ...

Dependency injection: How to pass the injection container around?

(This question does not rely on a specific IoC framework, so the interfaces and types in my samples are meta-types. Just replace them with the appropriate types for your favorite IoC framework in your head.) In my main methods, I typically set up my container doing something like this: static void Main() { IInjector in = new Inject...

Am I allowed to declare a lifecycle interceptor on an interceptor?

I have my business bean defined thus: @Local @Interceptors(BusinessInterceptor.class}) public class MyBean implements SomeBean { ... } And then I want my BusinessInterceptor to be configured with Spring's SpringBeanAutowiringInterceptor: @Interceptors(SpringBeanAutowiringInterceptor.class) public class BusinessInterceptor { @Auto...

Constructors + Dependency Injection

If I am writing up a class with more than 1 constructor parameter like: class A{ public A(Dependency1 d1, Dependency2 d2, ...){} } I usually create a "argument holder"-type of class like: class AArgs{ public Dependency1 d1 { get; private set; } public Dependency2 d2 { get; private set; } ... } and then: class ...

When to use an IOC container?

I'm trying to understand when I should use a container versus manually injecting dependencies. If I have an application that uses a 1-2 interfaces and only has 1-2 concrete implementations for each interface, I would lean towards just handling that myself. If I have a small application that uses 2-3 interfaces and each interface has ...

Windsor dependency

I have a class with constructor like this: public UserRepository(IBlockRepository blockRepos) { } and again, I have another class with the constructor like this: public BlockRepository(IUserRepository userRepo) { } this causes the Windsor error: Castle.MicroKernel.Handlers.HandlerException: Can't create component 'UserReposito...

How do I export and import application services with say MEF?

I'm working with MEF right now, but the answer I'm looking for probably is irrelevant to MEF -- it's all dependency injection -- I'm just using MEF terminology as an example here. Short background story, I read this article over at MSDN with focus on Composite Applications In this figure there's three things, the shell, the application...