Adding services after container has been built

Paul Knopf picture Paul Knopf · Feb 15, 2011 · Viewed 16.8k times · Source

Is it possible to register a service at run-time, meaning after the ContainerBuilder has been built and the Container has been created (and ContainerBuilder disposed of)?

Answer

Peter Lillevold picture Peter Lillevold · Feb 15, 2011

Yes you can, using the Update method on ContainerBuilder:

var newBuilder = new ContainerBuilder();
newBuilder.Register...;

newBuilder.Update(existingContainer);