1

1) Autofac and Ninject, which one is better in contextual binding?

2) With Ninject, I can bind to types in a specific namespace:

Bind<A>().To<B>().When(context => 
    context.ParentContext.Binding.Service.Namespace == "MyProject.Common");

Can I do this with Autofac?

Thanks!

(sorry for my English)

1 Answers1

2

Of the two, only Ninject provides this functionality.

It is a useful feature but Autofac excludes it to prevent fragility in other Autofac-specific features that rely on the dependency being unaware of the dependent component.

If you have a scenario that would benefit from this kind of behaviour in Autofac, feel free to post it and I'll have a shot at translating it into Autofac's way of doing things :)

Hope this helps, Nick

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • Hi, I need to inject DispatcherNotifiedObservableCollection into (and only into) all ViewModels (located in MyProject.ViewModels) as ObservableCollection. Any workrounds? Thanks. –  Jan 30 '11 at 02:51
  • Definitely- not much space here, would you mind creating a separate question? Thanks! – Nicholas Blumhardt Jan 30 '11 at 09:48
  • Thanks, I've created a new question at here: http://stackoverflow.com/questions/4846168/use-autofac-to-bind-types-in-a-specific-namespace –  Jan 30 '11 at 23:02