dependency-injection

Performance problems from dependency injection

In my profiler reports I'm increasingly seeing the results of mock-based testing with dependency injection. Many of the dependencies were static, but because we want to test methods in isolation they are changed to instance members, like the following example: class ShortLivedThing { IDependency1 dep1; IDependency1 dep2; IDepe...

Does anyone have a good analogy for dependency injection?

Hello, I have read a lot of articles on Dependency Injection as well as watched a lot of videos, but I still can't get my head around it. Does anyone have a good analogy to explain it? I watched the first part of the Autumn of Agile screencast and still was a little confused. ...

How to wire Interdependent beans in Spring?

I want to declare two beans and instantiate them using Spring dependency injection? <bean id="sessionFactory" class="SessionFactoryImpl"> <property name="entityInterceptor" ref="entityInterceptor"/> </bean> <bean id="entityInterceptor" class="EntityInterceptorImpl"> <property name="sessionFactory" ref="sessionFactory"/> </bean> But...

Is it possible to dynamically inject the attribute using IoC like Ninject or other IoC?

I am extending my Object Property Value Diff but I realized if an object has too many properties I may not want to diff them all. So I came up with the public class IgnorePropertyDiffAttribute : System.Attribute { } so that I can mark the properties I want the diff to ignore. However I don’t want to pollute my domain object with [Ign...

Ninject on asp.net Session state

I'm working with Ninject on a web application, using the BasePage and BaseMaster from the frameworks's integrations. What I would like to do is have an object injected and have a new instance created on each session. I've looked at the OnePerRequest behavior and it's close, but not quite. What I'm doing is performing a lot of calculati...

Going bananas with loose coupling and dependency injection.

With the latest additions to our dependency injection framework (annotations in spring), the marginal cost of creating DI-managed components seems to have hit some critical new threshold. While there previously was an overhead associated with spring (tons of XML and additional indirections), dependency injection seems to have started goi...

Using PowerMock or How much do you let your tests affect your design?

I've been a fan of EasyMock for many years now, and thanks to SO I came across references to PowerMock and it's ability to mock Constructors and static methods, both of which cause problems when retrofitting tests to a legacy codebase. Obviously one of the huge benefits of unit testing (and TDD) is the way it leads to (forces?) a much...

Decorator Chaining of Repositories and Specialized Repositories with Dependancy Injection

Right now I'm trying to figure out a way to do things smarter, and in the course of doing so all i've managed to do is use a full bottle of excedrin in a single day. Assume i have an interface called IRepository like so. public interface IRepository<T> { T Get(int id); void Add(T value); void Update(T value); void Del...

Structure Map configuration

Consider the following class public class SchemaExecutor: ISchemaExecutor { public SchemaExecutor(SqlPlusSettings sqlPlusSettings) { _sqlPlusSettings = sqlPlusSettings; } ... And container configuration ObjectFactory.Initialize( x => { SqlPlusSettings sqlPlusSettings = GetSqlPlusSettings(); x.ForRequestedT...

Dependency Injecting an HTTPModule

Google/MyBrain are failing me. Without using a framework (which I'll never get past my colleagues), how do you inject a dependency into an HTTPModule given that you (the programmer) are not in control of creating the instance? Are we into hacking up custom web.config sections + reflection or is there something cleaner I'm not seeing? e...

Dynamically Load HTTP Modules, Possibly with Unity?

Has anyone seen any how-to, documentation, or otherwise about how to load HTTP Modules dynamically for IIS? Basically what I am trying to do is to load HTTP Modules, which I'll call HTTPModuleA, HTTPModuleB, and HTTPModuleC. The modules however could be changed out at any time with HTTPModuleD, HTTPModuleE, or HTTPModuleF. I basically...

IoC/DI Container that supports Compact Framework

Hi, Is their any IoC controllers available that will work on .NET Compact Framework? ...

Introducing an IoC Container to Legacy Code

I'm writing a new .NET library for internal use at my company that will use IoC through Dependency Injection. Naturally, this library will be much easier to use if we use an IoC Container to resolve instances. However, the code that will be making calls into this library does NOT currently use Dependency Injection of any sort, and refa...

Is there a .NET IoC that prefers convention over configuration?

Simply put, if you had to use a IoC/DI container, thats easy to deploy (not a big fan of using config/xml file for everything), stable, good documentation and supports .net, which one would it be? It could just be me but too many xml files like one for the app, a few for ORM, a few for another component kinda gets overwhelming at times....

Projects with browsable source using dependency injection w/ guice?

I often read about dependency injection and I did research on google and I understand in theory what it can do and how it works, but I'd like to see an actual code base using it (Java/guice would be preferred). Can anyone point me to an open source project, where I can see, how it's really used? I think browsing the code and seeing the...

Felix/OSGi: How to use SCR components that are not OSGi services?

Apache Felix's SCR allows to declare (via annotations or XML) components that will then be instantiated, hooked up to their dependencies, and registered as OSGi services. It is also possible to skip the service registration part, and just have SCR create the component (by specifying @scr.component, but omitting @scr.service). I was thin...

How to resolve instances with constructor parameters in custom IOC Container?

I'm trying to build my own inversion of control container. Right now I store the objects with their types in a dictionary and resolve a reference when asked. But I want to make it possible to resolve a reference or a new instance. I can create a new instance with the Activator class. But, what if the constructor of the object to resolve...

Convention over Configuration go against loose coupling?

Something a lot of programmers seem to be abiding by is Convention of Configuration. In the context of IoC this means using the API instead of XML configuration. How are you supposed to keep the loose coupling idea behind DI/IoC when you have to reference the DLL containing the concrete implementations of the abstract interfaces/classe...

Dependency Injection Startup Performance

I recently was asked to troubleshoot some performance problems in an application built with Microsoft's Composite UI Application block - specifically that it was taking too long to load. This is built around Microsoft's ObjectBuilder dependency injection framework, which uses reflection/attributes to register classes. Profiling indicate...

Which Java Web Framework fits best with Google Guice?

I'm planning to start on a new project and am looking at the current state-of-the-art Java web frameworks. I decided to build my application around Guice, and am likely to use a very lightweight ORM like Squill/JEQUEL/JaQu or similar, but I can't decide on the web framework. Which one would fit best in such a lightweight environment? And...