Bootstrapper 2.0 guide

Extensions

Bootstrapper relies heavily on the plugin pattern for extensibility. In Bootstrapper each plugin is called an extension and its usually packaged in it's own assembly. To use an extension you need to add a reference to the extension's assembly and then you can use the Extension method as seen below
Bootstrapper.With.Extension(new AutoMapperExtension()).And.Extension(new NinjectExtension()).Start()
For convenience all the bootstrapper extensions provide static methods that can be used instead of using the Extension() syntax
Bootstrapper.With.AutoMapper().And.ServiceLocator().And.Ninject().Start();

Execution

When the Start method is invoked. Bootstrapper will scan the list of extensions that were declared and will invoke the run method of each one in the order that they were declared. This is important to note if, for example you want your startup tasks to use an initialized container, make sure to declare the container extension before the startup task extension. For example
Bootstrapper.With.StructureMap().And.StartupTasks().Start();
Some extensions like StartupTask and Automapper will make use of the container if it is declared and initialized to get a list of maps or registration classes. However, if the container is not present or not initialized then these extensions will use reflection to find maps and registration. That means that both of these statements will succeed.
Bootstrapper.With.Unity().And.AutoMapper().And.StartupTasks().Start();
Bootstrapper.With.AutoMapper().And.StartupTasks().And.Unity().Start();
Calling the Reset() method will call the reset method of each extension in the reverse order that they were added. Again, if you have a startup task that will use the container in the Reset method then make sure that the Container gets added before the StartupTasks extension like below:
Bootstrapper.With.Windsor().And.StartupTasks().Start();
//... later
Bootstrapper.Reset();

Assemblies

Bootstrapper scans the application's assemblies looking for implementations of specific interfaces like IMapCreator, IStartupTask, etc.. The default behavior is to scan all the loaded assemblies, so in most cases you don't have to indicate to Bootstrapper where to look for things. However, you can specify specific assemblies to include or exclude in bootstrapper's execution.
To exclude an assembly or assemblies you only need to specify the assembly name or part of it with the Excluding syntax as seen in the example:
Bootstrapper.Excluding.
    Assembly("log4net").        //excludes log4net.dll
    AndAssembly("Microsoft").   //excludes all assemblies 
                                //where the name starts with
                                //Microsoft like Microsoft.Csharp
    Start();
Many extensions exclude assemblies they depend on to improve the performance of Bootstrapper. For example, the AutoMapper extension excludes Automapper.dll, The Windsor extension excludes all assemblies starting with "Castle", etc.

In the case where an assembly containing maps or tasks or registration is not loaded when Bootstrapper executes it might be necessary to use the Including syntax to add it to the list of assemblies that Bootstrapper will scan. Unlike Excluding(), Including doesn't take a name or part of it, instead it expects an assembly. For example:
Bootstrapper.Including.
    Assembly(Assembly.GetAssembly(typeof(MyMapCreator))).
    AndAssembly(Assembly.GetAssembly(typeof(MyTasks))).
    Start();

New in 2.0.1.1!
Additionally, Bootstrapper can be told exactly where to look for things using the IncludingOnly syntax. Like Including(), this method expects an actual assembly. For example:
Bootstrapper.IncludingOnly.
    Assembly(Assembly.GetAssembly(typeof(MyMapCreator))).
    AndAssembly(Assembly.GetAssembly(typeof(MyTasks))).
    Start();     

New in 2.0.3.9!!
By default Bootstrapper scans the Loaded Assemblies to look for types. However, in the case of web applications, this behavior can become problematic when IIS recycles. For that reason Bootstrapper now provides an option to specify where to look for types with the LookForTypesIn syntax.
By the default the value is LoadedAssemblies but for Web projects (Asp.Net, Mvc, WCF,etc.) it is possible to use the value ReferencedAssemblies. For example:
//Loaded Assemblies
Bootstrapper.LookForTypesIn.LoadedAssemblies().Start();
//Same effect as
Bootstrapper.Start();
//Only for Web projects (Asp.Net, MVC, Wcf, etc.)
Bootstrapper.LookForTypesIn.ReferencedAssemblies().Start()

The Extensions

Details on how to use each extension can be found by clicking on the following links

Last edited Jul 29, 2013 at 3:30 AM by luisbocaletti, version 17

Comments

No comments yet.