dependency-injection

How do you pass an object to a windsor container instead of a type?

I have the following class: public class ViewPage<TView,TPresenter> : Page where TView : IView where TPresenter : Presenter<TView> { public ViewPage() { if (!(this is TView)) throw new Exception(String.Format("The view must be of type {0}", typeof(TView))); IWindsorContainer container = new WindsorContainer(); container.A...

Which Dependency Injection Tool Should I Use?

I am thinking about using Microsoft Unity for my Dependency Injection tool in our User Interface. Our Middle Tier already uses Castle Windsor, but I am thinking I should stick with Microsoft. Does anyone have any thoughts about what the best Dependency Injection tool is? Autofac Castle MicroKernel/Windsor ObjectBuilder PicoContainer...

Dependency Injection book recommendation(s)

It seems like there are very few books (yes, I read books) on Dependency Injection. The Amazon tag for "dependency injection" lists only a few titles, and all of them are specifically about Spring for Java. Are there any books out there that cover DI/IoC in general? Or any that include a survey of multiple DI frameworks? Or any that cov...

Python Dependency Injection Framework

Is there a framework equivalent to Guice (http://code.google.com/p/google-guice) for Python? ...

How should I order my ctor parameters for DI/IOC?

I'm a bit of a DI newbie, so forgive me if this is the wrong approach or a silly question. Let's say I have a form which creates/updates an order, and I know it's going to need to retrieve a list of products and customers to display. I want to pass in the Order object that it's editing, but I also want to inject the ProductsService and ...

Using Dependency Injection frameworks for classes with many dependencies

I have been looking at various dependency injection frameworks for .NET as I feel the project I am working on would greatly benefit from it. While I think I have a good grasp of the capabilities of these frameworks, I am still a little unclear on how best to introduce them into a large system. Most demos (understandably) tend to be of qu...

which scope should a DAO typically have.

its out of question that a dao will not hold any state. however, for easiest access to the class, is it better to use prototype( = new every time) or singleton? simple object creation is cheap for dao's.. it typically only holds a sessionfactory, accessing the object from a list of singletons may be equally expensive. clarfication: t...

How to read out/resolve properties from Castle Windsor config

I have a lot of castle xml configs where properties like connectionstring are also held under .Net configuration sections. I'd like to be able to read out the properties using the container but can't see a mechanism to do it. ie <castle> <configuration> <properties> <connectionString>Data Source=MyServer;Initial Catalog=Y...

Inject dependencies in methods or in the constructor?

Dependency injection seems to be a good thing. In general, should dependencies be injected at the methods that require them, or should they be injected in the contructor of the class? See the samples below to demonstrate the two ways to inject the same dependency. //Inject the dependency into the methods that require ImportantClass Cl...

Why exactly isn't MEF a DI/IoC Container?

It's been said on the blogosphere and by MS themselves that MEF isn't another IoC Container. Ok...but why? It seems the same to me. Maybe it's not as good as Unity or castle Windsor, but it still fits the definition, doesn't it? Can anyone explain why MEF isn't an IoC Container like Unity or Castle Windsor? ...

Injecting dependency to Linq to Sql

Is there a mechanism to inject dependencies into Linq to Sql or entity framework entities? If so would it be a sensible approach? ...

DI- Dynamic parameter of type Type where type is the parent objects type

Hi guys I have a dependency that I need to inject into one of my classes. This dependency will be lifestyle of Transient. It inturn has a dependency of type Type. This type should be the type of the original class. I was just wondering if anyone has any idea how I might go about conducting this registration. See example: public interfa...

How do I inject a WebRequest/Response dependency?

I'm struggling to separate the dependencies in the following code: public static SiteConnector ConnectToSite(String Logon, String Password) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_URI); ConfigureRequest(Logon, Password, webRequest); HttpWebResponse webResponse = (HttpWebResponse)...

Practical Singleton & Dependency Injection question

Say I have a class called PermissionManager which should only exist once for my system and basically fulfills the function of managing various permissions for various actions in my application. Now I have some class in my application which needs to be able to check a certain permission in one of its methods. This class's constructor is c...

Inversion of Control with .net

It's rare that I hear someone using Inversion of Control (Ioc) principle with .Net. I have some friends that work with Java that use a lot more Ioc with Spring and PicoContainer. I understand the principle of removing dependencies from your code... but I have a doubt that it's so much better. Why do .Net programmers not use (or use les...

Which Inversion of control (IoC) containers support .NET 1.1?

(see title) ...

How to avoid circular data-access object dependencies when you need to do lazy loading (and using an IOC Container)?

Note: The examples below are C# but this problem should not be specific to any language in particular. So I am building an object domain using a variant of the S# Architecture. For those unfamiliar with it, and to save you some reading time the idea is simply that you have a Data Access Object Interface for each of your domain objects ...

How to inject a changing dependency

I'm new to dependency injection, I'm wondering how you would handle the following scenario. We have something like the following: public class DatabaseContext { public string ConnectionString {get;} } public interface IDataAccess { string GetString(int id); } public class DataAccessImpl : IDataAccess { private DatabaseContext _...

Measuring Testability of C# code

Having come across a link on stack overflow, I have found the writings of Miško Hevery very engaging reading. So good that I am seeing a new approach to what I previously thought I was doing quite well. He talks mainly about Dependency Injection, Automated Unit Testing and Good Design. A number of the good practices he advocates are t...

Ruby dependency injection libraries.

I've been looking at some Ruby dependency injection libraries. In particularly, I checked out Needle and Copland. They've been around for quite awhile, yet not a lot of usages. What are some of the pros and cons of using these two libraries? It sure seems like a lot of libraries / frameworks out there could make good use of these t...