Rebuild IoC Container

Nov 5, 2013 at 5:14 AM
is there a sample to rebuild the container or override the IoC registration? i'm using autofac and trying the following but it is not overriding / rebuilding the container
Bootstrap.Bootstrapper
                .Excluding.Assembly("Microsoft") //excludes
                .With.AutoMapper()
                .And.Autofac().WithContainer((IContainer)Bootstrapper.Container)
                .UsingAutoRegistration()
                .Including.LookForTypesIn.LoadedAssemblies()
                .Start();
Coordinator
Nov 6, 2013 at 1:34 AM
I'm not sure of what you mean by override.
If you want to clear the container and register things again you could try calling Bootstrapper.Reset before the code that you have here (minus the WithContainer clause)

Let me know if that works

Thanks

Luis
Nov 12, 2013 at 9:55 AM
Edited Nov 12, 2013 at 9:56 AM
Bootstrapper.Reset does not do anything.. Basically I need to add new/or override a registration in the existing container of the bootstrapper.. but how can I do that?
Coordinator
Nov 15, 2013 at 2:09 PM
Bootstrapper.Reset will call the reset method on each of the extensions registered in bootstrapper.
For example:
If you call
Bootstrapper
       .Excluding.Assembly("Microsoft") //excludes
       .With.AutoMapper()
       .And.Autofac().UsingAutoRegistration()
       .LookForTypesIn.LoadedAssemblies()
      .Start();
then your container is initialized. Later you can call
Bootstrapper.Reset();
now your container is empty again

to reinitialize you can call the whole thing again, adding new assemblies if needed.
Bootstrapper
       .Excluding.Assembly("Microsoft") //excludes
       .Including.Assembly(NewAssembly)
       .With.AutoMapper()
       .And.Autofac().UsingAutoRegistration()
       .LookForTypesIn.LoadedAssemblies()
      .Start();
I hope this helps. Although, I'm still curious why do you need to override a registration. Did you have new assemblies loaded?
Alternatively you could get the container from Bootstrapper and manipulate it directly like this
var container = (IContainer)Bootstrapper.Container;
// here you can add remove or update your container contents