views:

141

answers:

2

What is the most important features a IOC container should contain? You can easily create containers in 15 lines of code, but what should it include to be "useful" in a project?

+1  A: 

In descending order of importance:

  1. Allow at least setter and constructor injection,
  2. Separate configuration from code,
  3. Allow different styles of configuration (XML or annotations),

These will require more than 15 lines of code, but those seem key to me.

duffymo
+1  A: 

This is a pretty wide open topic, and given to a lot of subjectivity, but I will try and answer from a very pragmatic point of view. Given the projects that I have worked on, and my experience with IoC, I would say that there are at least three biggies to look for in terms of usefulness.

  1. Configuration - Any IoC that you use needs to have some central location that allows you to configure the behavior of that container. Whether that be a config file or a nice set of API calls that can be wrapped up in a global class somewhere, if the container isn't easily configurable then it is going to be a headache.
  2. Lifetime Management - You really want a container that has the ability to allow for varied object lifetimes. You might want a certain object to always get a new IPersonCreator, but you only want one IPersonService in existence at any given time.
  3. Automatic Dependency Injection - Ok, so Dependency Injection is the concept that IoC is built on top of, but you don't want to have to manage this yourself. The idea here is that if you ask for an IPersonCreator for the first time, it should resolve all it's dependencies, and their dependencies and so on automatically.

Overall what you need depends on the project, but there are several containers out there that will suit your needs just fine.

Josh