tags:

views:

397

answers:

2

I've been trying to integrate the latest version of autofac (1.3.3.54), and I'm running into the following problem.

The recommended way of consuming parameters in the Register callback, per the Google code wiki for the project is as follows:

builder.Register((c, p) => new Foo(p.Get("arg1")));

However this won't compile with the mentioned version of the autofac code. I looked through the source and I see that p is an IEnumerable (ComponentActivatorWithParameters). Is the code out of date with respect to the documentation?

+3  A: 

It appears that the code has changed and the documentation on the Wiki has not been updated. The "Get" method is now "Named" and the "Parameter" class is now "NamedParameter". See the following example:

var builder = new ContainerBuilder();
builder.Register((c, p) => new Person(p.Named<string>("name")));

using (var container = builder.Build())
{
    var person = container.Resolve<Person>(new NamedParameter("name", "Fred"));    
}

Hopefully someone can update the documentation soon.

Mark Lindell
Done, thanks for the pointer!
Nicholas Blumhardt
A: 

I've attached freshly built documentation for AutoFac 1.3 to AutoFac issue #121. I hope they'll resume posting official 1.3 documentation at least until they retire the 1.3 branch and, with it, support for .NET 2.0.

Garth T Kidd