I write integration tests for my application, and use my container for this. I want to be able to register all the components as I do in real running, and then override some
Autofac will use the last registered component as the default provider of that service
From the AutoFac documation.
In your arrange/setup/testInit phase register the mocks, then resolve the SUT:
[SetUp]
public void TestInit()
{
Mock mock = new Mock();
builder.RegisterInstance(mock.object).As();
...
...
_target = builder.Resolve();
}
Note:
Singletons, static members and SingletonLifestyle(registration) may cause some troubles....