Hi Jonathan,
Autofac won't choose private constructors. It is not a recommended
practice, however if you're stuck in that situation all is not lost.
Your best option is to implement IActivator. I'd like to say that
subclassing ReflectionActivator would do the trick, however the
necessary methods are private (I'll change this for 1.2.)
There are two members on it, ActivateInstance() and
CanSupportNewContext - the latter is a boolean property, just return
true in your case. Implementing ActivateInstance() isn't a big deal -
find your constructor and retrieve the appropriate values from the
provided IContext and IActivationParameters.
A copy/paste of the standard ReflectionActivator wouldn't be a bad
start.
With your custom activator (MyReflectionActivator) use the
RegisterComponent() method to plug it in:
builder.RegisterComponent(new Registration(new Descriptor(...), new
MyReflectionActivator(typeof(X)), new FactoryScope(),
InstanceOwnership.Container));
Not exactly beautiful but will do the trick. You could also just
create the reflection activator and call it from a delegate
registration, i.e.:
var myActivator = new ReflectionActivator(typeof(X));
builder.Register((c, p) => myActivator.ActivateInstance(c, p));
I raised issue 39 a little while ago with the intention of improving
the usability of the constructor selection API, I'll add a note
describing this scenario there (
http://code.google.com/p/autofac/
issues/detail?id=39.) I'm also looking at some related issues that
will allow bits and pieces of the Registration (the activator etc) to
be easily customised through the ContainerBuilder classes - that will
help in this scenario, too.
Cheers,
Nick