1

Why leaving StructureMap?

As stated by Jeremy Miller (The guy behind StructureMap): No Silverlight support

Why I need Silverlight support?

I'm starting to write WindowsPhone apps, so looks like I need this.

Purpose of this question?

I love StructureMap. It's full of features and I've been using it for many of my projects. But I have to choose a new one. Which one should I choose?

AutoFac?

Ninject?

Other tools?

What I want from new framework?

Supporting Windows Phone.

Right now I'm registering my singleton dependencies using StructureMap like this:

ObjectFactory.Configure(Function(config)
config.For(Of TPlugin).Singleton.Use(Of TConcrete)())

Or this (for generic types):

ObjectFactory.Configure(Function(config)
config.For(Of GetType(IRepository(Of ))).Use(Of GetType(Repository(Of )))())

Or forwarding types:

ObjectFactory.Configure(Sub(config) config.Forward(Of TResolveBy, TRequested)())

I want to do the same things with syntax near to StructureMap(or a better syntax)

What I want from you?

Do you have any experience with them?

Which one do you prefer?

Which one do you recommend to be used in a Windows Phone App?

Any other suggestions?

Update:

What about life cycle and initializing of the concrete type(using a function instead of just defining the type)? In StructureMap :

config.For(pluginType).Singleton.Use(concreteType)

or

config.For(Of TPlugin).HybridHttpOrThreadLocalScoped.Use(SomeFunction)
Afshin Gh
  • 7,918
  • 2
  • 26
  • 43
  • Really? 1 down vote & 1 close request for this question? Can I ask why? – Afshin Gh Jun 28 '12 at 11:10
  • 2
    Probably because the question isn't technically answerable - it's opinion-based or subjective rather than objective. For example, if both Ninject and Autofac support Windows Phone, then which you choose is a matter of preference, not necessarily technical merit. http://blog.stackoverflow.com/2010/09/good-subjective-bad-subjective/ – Travis Illig Jun 28 '12 at 14:44
  • 1
    I'm asking from fellow developers about an IoC container that can support Windows Phone and I'm asking from them about their experience with that tools. I found out about SimpleContainer because of Derek's answer. I learnt from Stripling about syntax of Ninect. If both of them supports WP7, I'll will not choose one of them based on my preference. Answers to this question will help me choose. So please grove up and STOP down voting every thing! – Afshin Gh Jun 29 '12 at 11:46

4 Answers4

1

When I did some research a while back to decide what DI framework to use, I found that a lot of people seemed to favor Ninject. I've been using it ever since, and loving it. Remo Gloor has done some really great work with it and its various extensions, and we just upgraded to Ninject 3 a few days ago.

The binding syntax is pretty simple. I usually use a NinjectModule subclass and say (in C#):

Bind<TPlugin>().To<TConcrete>()

... which I believe is pretty similar to what you're doing now.

StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
1

I do recommend Ninject. I use it for all my projects mainly because of its auto-binding feature, that allows you to put together interface and its implementation automatically without explicit configuration (like in your samples) - example can be found here.

And you can still use manual configuration just like in your code samples - check out Ninject documentation for examples.

It seems to support Silverlight as well, so it should be usable for you.

EDIT:

As per StriplingWarrior's comment, the way auto-binding syntax works has changed in recent version of Ninject - check out this SO question for details.

Community
  • 1
  • 1
Nikola Anusev
  • 6,940
  • 1
  • 30
  • 46
  • 2
    +1. Just a quick note: the convention binding syntax has changed in Ninject 3. Here's an example: http://stackoverflow.com/a/9868159/120955 – StriplingWarrior Jun 27 '12 at 19:26
  • 1
    Warning: Silverlight != Silverlight for Windows Phone. There is a crucial part missing on the WP7 version of Silverlight, which is lightweight code generation (LCG), which is needed to compile Expression trees. Many containers use LCG or Expression trees to optimize code. So are you sure Ninject has a Silverlight version for Windows Phone as well? – Steven Jun 30 '12 at 00:30
  • @Steven I am. See http://www.ninject.org/download.html - there is WP7 version available. – Nikola Anusev Jun 30 '12 at 06:53
  • Thanks a lot from both of you guys(Steven & Nikola) – Afshin Gh Jun 30 '12 at 08:23
1

I'm using SimpleContainer that's packaged with Caliburn Micro. IOC Battle–Revisited

Update: there is also a separate nuget package for SimpleContainer.

Derek Beattie
  • 9,429
  • 4
  • 30
  • 44
0

Who needs an IoC tool? The Factory and Abstract Factory patterns are easy, awesome, and you never have to wonder if they support technology XYZ.

tallseth
  • 3,635
  • 1
  • 23
  • 24
  • 1
    Lots of great open source applications out there are using IoC tools. I have nothing against Factory Pattern, but I find Repository & Unit of Work more interesting and I think using IoC is a better approach. – Afshin Gh Jun 28 '12 at 11:12
  • 2
    Factory and Abstract Factory patterns make it difficult to write self-contained unit tests, whereas DI makes it easy to use a mocking framework or fake implementations to set up the scenario you want to test. When done right, you don't have to worry about DI supporting a given technology, either. The vast majority of your code is completely agnostic of the IoC container you use. – StriplingWarrior Jun 28 '12 at 15:29