4

I just started learning Unity yesterday, gave up on it b/c of the lack of examples. I moved onto Castle Windsor because they seemed to have the most documentation/activity. however, I reached a point on their tutorial which they don't explain. To me, this means they've assumed that I have this knowledge. Not only that, but their downloadable example project wasn't compatible with VS2010 - I had to hack the .csproj file just to get it working.

I've seen the many articles on .net IOC containers, but my question is 'which is best for the beginner?'. I want to learn this, but find it frustratingly difficult when a thorough tutorial doesn't seem to exist.

To throw another frustrating aspect out there - I've only worked with vb.net, and all the examples out there use c#. I know they are basically the same language, but it is none-the-less annoying to have to keep using the code-converter, and then figure stuff out when it doesn't work. I can't use c# b/c of co-workers who might in the future have to change the code.

Edit: I would define 'easy to learn' as, in order of preference: tutorial/documentation/mailing list or forum

Phil
  • 321
  • 2
  • 14
  • 3
    You could read my book: http://affiliate.manning.com/idevaffiliate.php?id=1150_236 – Mark Seemann Feb 25 '11 at 20:19
  • The tutorial is a work in progress. We're very open for feedback so feel free to point out areas that don't explain something well enough and we'll improve it. We also accept suggestions as to where to take the tutorial next, what areas to cover in next parts – Krzysztof Kozmic Feb 25 '11 at 21:55
  • Also why the project was not working in VS2010 for you? It is being developed in VS2010 so I don't see why it wouldn't work – Krzysztof Kozmic Feb 25 '11 at 21:56
  • As for VB - I'm happy to accept tutorial in VB to the wiki if someone contributes it, but I doubt any of the main contributors to Castle would be willing to write one themselves – Krzysztof Kozmic Feb 25 '11 at 21:57
  • I just noticed your comments Krzysztof - Thanks for your interest and I will address them monday when I'm back at work. Got a weekend to enjoy : ) – Phil Feb 25 '11 at 22:39
  • 1
    Possible duplicate of http://stackoverflow.com/questions/2194265/i-am-looking-for-a-simple-yet-practical-and-robust-ioc-di-framework-for-net – Maxim Gueivandov Feb 25 '11 at 23:42

4 Answers4

2

Seems like this question always comes up... its a matter of preference, unity is quick, dirty, but documentation is thin. But then again most MS documentation is thin.

I have used Unity in the past and it has pretty much done everything I needed it to.

If you are looking for alternatives Scott Hanselman has a blog that goes through them

Grant Palin
  • 4,546
  • 3
  • 36
  • 55
Nix
  • 57,072
  • 29
  • 149
  • 198
  • Well, I don't see it as a matter of preference because some are easier to learn than others. Defined by amt. of documentation/tutorials/less assumed knowledge/etc. – Phil Feb 25 '11 at 19:33
  • It is a mater of preference, especially if you are just trying to learn about the concepts of DI. You are just learning right? Most OTFS libraries come with lame documentation and either out of date, incomplete, broken, or useless examples, knowledge is earned by fumbling through your own creations. Since you are just trying to learn you dont need to worry about functionality, what it provides, or if it will meet the needs of your system (Mocking, Annotations, external configs, etc) which makes it a mater of preference. – Nix Feb 25 '11 at 19:34
  • Yeah, after trying both unity and windsor, I guess I could try a different approach. I'm just so comfortable with the read->tutorial->read->create sequence which has served me well. Thanks for the suggestion. And if you don't mind me asking, would you know whether it's used enough in companies for me to bother learning? – Phil Feb 25 '11 at 19:43
  • If you are asking about Castle Winsor and Unity they are used a lot. Ninject is also a very popular one.. I never find the tutorials very useful, they always seem to be to dry, or to shallow. They are never really in depth or "real world." – Nix Feb 25 '11 at 21:15
1

It might help if you explain what your problem is; it's easier for the community to resolve specific problems than answer "is there an easier solution that doesn't require me to understand something that I am not articulating". However, it would be a good idea to make sure you're comfortable with Fowler's articles on the subject ( http://martinfowler.com/articles/injection.html and http://martinfowler.com/bliki/InversionOfControl.html ). If you understand those articles, you'll be in a better position to ask questions that are specific to your problem domain.

To directly answer your question, however, I found Ninject to be the most intuitive dependency injection framework, thanks mostly to a fairly pleasant fluent interface for binding. StructureMap was almost as pleasant. I have limited experience with Castle Windsor, usually only incidental use in other projects. I worked from the SharpArchitecture project sample and replaced Windsor with Ninject on previous projects.

As for use of a DI library, the most important thing, in my experience, is to limit the span of control of your DI framework to a relatively small footprint. For example, I find that, in web applications, DI containers are generally best when they are only invoked by your ControllerFactory.

The most tedious DI container that I've worked with was in Spring (though I'm sure it's better than when I last used it), but there are some really excellent examples on how to use it since it has been so influential in both the Java and .Net community.

Edit: Presuming your goal is to learn how DI can be applied in a not-completely-trivial sample project, consider looking at the example project that ships with SharpArchitecture (probably after reading the tutorial on SharpArchitecture's web site). See http://www.sharparchitecture.net/

The sample project is in C#, and SharpArchitecture's toolkit encompasses a lot more than dependency injection, but that should take you a lot further than most of the trivial sample projects I've seen online.

JasonTrue
  • 19,244
  • 4
  • 34
  • 61
  • Well, I don't really know how to make is more specific. I obviously don't have the ability to choose a good beginner framework, because i've tried 2. I don't want to keep going with windsor or unity, because they seem to be for people who have fiddled with it before. My problem is that I want to know a framework which I should start off on. What would you suggest my question be other than that? – Phil Feb 25 '11 at 20:28
  • I provided guidance on which frameworks are the easiest to work with based on my experience; it's not clear to me what problems you are having, which makes it difficult to provide more specific guidance. – JasonTrue Feb 25 '11 at 21:01
  • I see where you're coming from now. I should have explicitly said how I learn, since people learn in different manners. I will edit my post. Thanks for your suggestion though, I will definitely try out ninject. – Phil Feb 25 '11 at 21:38
0

I think the thing you need to grok first is the concept of DI and what it gives you. Once you understand that learning the different implementations is much easier.

So my answer to your question is: "Your own" that is the easiest DI framework to learn.

Learn the basics of DI and then build your own simple container and it will make things clearer IMO. You can build your own DI framework in an hour or two.

James Kovacs has a great intro to DI http://msdn.microsoft.com/en-ca/magazine/cc337885.aspx

Martin Fowler has two great articles explaining the concepts http://martinfowler.com/bliki/InversionOfControl.html

http://martinfowler.com/articles/injection.html

Brad Cunningham
  • 6,402
  • 1
  • 32
  • 39
  • I did come across an article that explained how to build my own. I quickly decided not to because I've been diving into web frameworks and been successful with that. I thought I could do the same with IOC, but maybe not. Giving this a try atm - thank you. – Phil Feb 25 '11 at 20:31
  • Windsor's documentation puts heavy emphasis on explaining concepts and patterns not just API. Also make sure you read the FAQ and articles it links to. – Krzysztof Kozmic Feb 25 '11 at 21:59
  • Yeah - I think part of the problem is that without concrete examples, I tend to get bored/lost and just move on. The tutorials help me in the fact that I have something to look back on when reading the new concepts and patterns. I just seem to need that concrete aspect before the abstract stuff sinks in. – Phil Feb 25 '11 at 22:48
-1

I've used Unity which is from Microsoft and part of the Enterprise Library. It provides both configuration-based and code-based mappings.

There's a good intro here:

http://msdn.microsoft.com/en-us/library/ff650320.aspx

Shane Andrade
  • 2,655
  • 17
  • 20
  • I definitely saw that one, but due to its outdated content, looked and found this one instead. [Unity Intro](http://msdn.microsoft.com/en-us/library/ff649614.aspx) The problem is that they don't have a tutorial. When I was reading through the configuration portion, nothing was explained concretely. Especially when it came down to the debate 'whether or not to configure via xml or code' – Phil Feb 25 '11 at 19:28