I'm starting to use Autofac and I can't seem to find an answer to this question.
Also, when should I call ContainerBuilder.Build() ?
After I call the ContainerBuilder.Build() is it possible to register another type or instance?
AutoFac provides better integration for the ASP.NET MVC framework and is developed using Google code. AutoFac manages the dependencies of classes so that the application may be easy to change when it is scaled up in size and complexity.
Autofac is an IoC container for Microsoft . NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity.
I can't tell you whether or not the Build method is expensive or not, but if you follow the Register Resolve Release pattern it doesn't matter because you should only have a single container instance per application.
You need to invoke the Build method once to get a container instance, so no matter how expensive (or not) it is, this is a cost you must pay. However, when you only use a single instance of the container, you only pay that cost once.
ContainerBuilder.Build() should generally be called during application startup before you actually start invoking business behavior.
If you need to register additional components into an existing container you can. To do this in Autofac v2.2 (or later), you can create another ContainerBuilder instancer and use the ContainerBuilder.Build(IContainer) overload method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With