dependency-injection

I'm using Dependency Injection: which types should I bind as singletons?

There are a lot of questions out there about whether singletons are "bad," and what patterns to use instead. They're generally focused on the singleton design pattern, which involves retrieving the singleton instance from a static method on the class. This is not one of those questions. Ever since I really "discovered" dependency inject...

Ninject with Windows Application

I want to use Ninject in my Windows application and I want to know if there is best practices that I can do; strategies to find a balance between performance and maintenance. The problem with Windows application and Web application is that in Web application, there is a scope easy to define that is the context but with Windows applicati...

How to use a custom IoC in asp.net website?

I am trying to write a simple IoC library, and i am going to use it in asp.net websites. My Question is: Should i cache all the registered objects "i add this in Dictionary<Type, object>" and use the cached objects each request? ,or should i resolve them each time page loads or on a new request? And does the exist tools such as unity ha...

How, for example, to make a binding with constructor arguments to a Bitmap with Ninject?

I currently have a class of this form: class Abc { private readonly IDisposable disposable; public Abc(IDisposable disposable) { this.disposable = disposable; } ... } Now, I'd like to know how can I make a binding of IDisposable to Bitmap using the Bitmap(int widht, int height) constructor. I've tried w...

Dependency Injection Gotchas...

Does anyone have a list of link(s) on the www for a good list of DI gotchas? I have been trying to inject controls using DI, in an asp.net webforms app and found that on recursive build up that ViewState is lost. Also would be helpful a list of articles where the developer needs to be aware to gotchas before taking teh big step in implem...

Design question regarding Dependecy Injection and reuse of a single data context

I'm currently just starting to implement Dependency injection so i can start testing my code and have come across an issue many of times that i cant figure out. My current case scenario: I have a single class ( foo.cs ) that is active the whole time a windows service is running. Its responsible for polling the db for new messages then ...

Injecting fields via Spring into entities loaded by Hibernate

I am looking for a way to inject certain properties via Spring in a bean that is loaded from the DB by Hibernate. E.g. class Student { int id; //loaded from DB String name; //loaded from DB int injectedProperty; //Inject via Spring } Can I configure Spring so that whenever Hibernate creates objects of class Student, some pro...

Cyclic dependency with ninject

I'm trying to figure out correct way how to bind something like this with ninject. interface IMainService { void DoStuff(); } interface IOtherService { void DoSomeMagic(); } abstract class BaseClass { //many stuff here } class MainClass : BaseClass, IMainService { public MainClass(IOtherService s) { } pub...

Is it possible to use multiple @Qualifier annotation in Spring?

I have a set of beans that are characterized by two properties. They are basically serializers for different classes and for different purposes. For example, there may be an Order serializer for local log, Order serializer for logging webservice call, Customer serializer for tracking URL and Customer serializer for tracking URL. This ...

How to choose between methods of acquiring dependencies?

I've seen at least three ways of acquiring dependencies in a Java object without coupling the object to the creation of the dependency; Dependency Injection - some framework injects a required object into another object based on an external configuration, example: Spring managed beans Dependency Lookup - a class looks up a required dep...

Construtor/Setter Injection using IoC in HttpHandler, is it possible??

Hi. I've ran into a rather hairy problem. There is probably a simple solution to this but I can't find it! I have a custom HttpHandler that I want to process a request, log certain info then enter the details in the database. I'm using NUnit and Castle Windsor. So I have two interfaces; one for logging the other for data entry, which a...

Rhino Mocking and TDD with legacy code

Hi, First of all let me say I am working from legacy code. So some changes can be made but not drastic ones. My problem is I have a "Vehicle" object, it is pretty simple but has no interfaces or anything on it. This project was created before TDD really started to become more main stream. Anyway, I need to add a new method to change th...

Mocking without injection

Hello all, (C#, WCF Service, Rhino Mocks, MbUNit) I have been writing tests for code already in place (yes I know its the wrong way around but that's how its worked out on my current contract). I've done quite a bit of re-factoring to support mocking - injecting dependencies, adding additional interfaces etc - all of which have improve...

How to inject EJBs with custom injector?

How can I inject EJBs with my own injector? I have a distributed environment and a service locator, which can locate all EJBs. Is it possible to use the standard @EJB-Annotation, but make the lookup on my own? For example: @javax.ejb.EJB(name = "ejb/StackOverflow") private StackOverflow stackOverflowService; Should finally do: retu...

Using [ImportingConstructor] to import calling object into constructor parameter using MEF

I am in the process of converting some of my code to MEF from a proprietary system that sort of does the same thing as MEF, and I have a question about how I would accomplish the following problem that I recently ran into. I have a typical entity object that looks something like this: public class Account { [Import] public IAc...

Which is better: Dependency Injection+Registry or Dependency Injection or Global Registry?

Firstly, I want to restrict this question to web development only. So this is language agnostic as long as the language is being used for web development. Personally, I am coming at this from a background in PHP. Often we need to use an object from multiple scopes. For example, we might need to use a database class in the normal scope b...

How does Spring @Autowired work

I came across an example of @Autowired public class EmpManager { @Autowired private EmpDao empDao; } I was curious about how the empDao get sets since there are no setter methods and it is private. ...

How Dependency Injection Manually Implemented?

How we can manually inject an object without using the facility of containers. I did something similar through reflection as follows. Class actionClass = Class.forName("SampleClass"); Object actionObject = actionClass.newInstance(); Method reqMethod = actionClass.getMethod("setRequest", HttpServletRequest.class); reqMethod.invoke(action...

Static repository... can't use DI, what to do?

I am in a situation where we need to modify what is being returned from the static repository in a 3rd party open-source application (NopCommerce). The problem is that they use static repositories, so I can't merely inherit an interface and DI my own repository. I'm trying to do this without modifying the NopCommerce code-base... any f...

GlassFish, CDI and Constructor Injection

Is constructor injection supported in GlassFish 3.1's implementation of CDI for managed beans? I have a @Singleton EJB into which I want to inject another managed bean (contained in the same EJB module) using constructor injection. Field injection does work. But with constructor injection I get a NullPointerException from AbstractSinglet...