Some more insight into the autofac

Here are some updates:

  1. The code required to compile autofac against .NET 2.0 (in a single file) could be located here.
  2. As Nicholas pointed out, there is no need to register parent scope or do something exceptional about the lambda expression. The expression already evaluates against the current scope. This nicely deals with the previous Castle MicroKernel problem described here (what’s more important, it is easy to understand what and why happens behind the curtains). See his snippet below
ContainerBuilder cb = new ContainerBuilder();
cb.Register(c =>; new A(c.Resolve<B>())).
  WithScope(InstanceScope.Factory);

Container parent = cb.Build();

Container child = cb.CreateInnerContainer();

var childBuilder = new ContainerBuilder();
childBuilder.Register(c => new B());
childBuilder.Build(child);

A a = child.Resolve<A>();

More updates are to come. I’ll try to check out the following areas of the autofac IoC:

  • XML configuration (nothing exceptional is expected, but still you never know)
  • Lifestyles and scopes
  • Possibility of implementing the policy injection with the autofac (may be lambdas would aid a little bit here too…). It is always nice to know if you can route all your business objects through some fast IoC.

Leave a Reply