容器构建完成后添加服务

问题描述:

是否可以在运行时注册服务,这意味着在构建了 ContainerBuilder 并且创建了 Container(以及 ContainerBuilder代码>处置)?

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)?

是的,你可以,使用 ContainerBuilder 上的 Update 方法:

Yes you can, using the Update method on ContainerBuilder:

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

newBuilder.Update(existingContainer);