What Inversion of Control Container framework would you recommend to a beginner in this area?
views:
856answers:
7I have done some evaluation of the Spring.NET port. It offers AOP, config-file setup of the container, and other cool stuff. I think their site is well organized and the docs are well written.
James Kovacs did a dnrtv screencast where he shows how to create your own IOC container. I recommend this to a beginner not because it's necessarily the one you want to use but because it shows the basics of why you need an IOC container and what the basic functionality is. After this, try moving on to Castle Windsor or Structure Map.
I recall there are some really simple tutorials from BitterCoder on Castle's Windsor which I found helpful and easy to follow.
Even if you decide to use Windsor or not, those walkthroughs should still give you a good idea of the types of features / functionality to expect from other containers.
- Part 1 - Simple Configuration
- Part 2 - More Configuration (Arrays)
- Part 3 - Still More Configuration (Dictionaries)
- Part 4 - Switching Configurations
- Part 5 - Configuration Parameters
- Part 6 - Switching Between Lifestyles
- Part 7 - Switching Implementations
- Part 8 - Referencing Implementations By Key
- Part 9 - Constructor Injection
- Part 10 - Setter Injection
- Part 11 - Factories
- Part 12 - Decorators
- Part 13 - Injecting Service Arrays
- Part 14 - Startable Facility
I would say StructureMap. It is one of the more mature framework and really easy to use. Moreover it can integrate well with NMock to create mock objects which are invaluable for unit testing. The Microsoft supported framework is Unity so you may look at that as well.
I agree with dp. The author of that screencast even says that you should roll your. This is so you will know how they work. Then once you have that down you can move on to the more full featured one's.
It has also been mentioned that there really isn't that a 'one IOC container to rule them all'. This is because they pretty much all have the same features. It comes down to which implementation you favor. For instance, if you are using the Enterprise Library Framework then heavily then you might favor the Unity container because you get free tie-ins to the rest of EntLib. Or maybe you are allergic to XML then you can use Ninject which has a very nice fluent interface. Each framework has its strengths and weaknesses but they will pretty much be the same from the beginners stand point.
Lightweight, simple, fast, C# 3.0-oriented and works (for me) better in complex projects than any other IoC Container (even Windsor).
Primary features:
- Deterministic disposal of components
- Expression-based configuration
- Proper support for multi-scoped component resolution
- High performance
- Lean codebase