The bootstrapper is the easiest way to configure an engine, add pipelines and modules to it, and process command-line arguments.
Creating A Bootstrapper
A bootstrapper can be created using the static Bootstrapper.Factory
property:
using System;
using Statiq.App;
namespace MyGenerator
{
public class Program
{
public static async Task<int> Main(string[] args) =>
await Bootstrapper
.Factory
.CreateDefault(args)
.RunAsync();
}
}
When using Statiq Framework you can create a bootstrapper with the .CreateDefault(args)
method on the Factory
. Other Statiq projects like Statiq Web often have other factory methods like .CreateWeb(args)
.
The bootstrapper exposes a fluent API very similar to how ASP.NET Core and other modern .NET projects are provisioned.
Default Behavior
The bootstrapper does a lot by default when you call .CreateDefault(args)
. However, if you'd rather have more control over any of the default behavior, you can call a different creation method:
Create(string[] args)
will create the bootstrapper without any default behavior and it will be up to you to add any default behavior you want using other fluent methods.CreateDefault(string[] args, DefaultFeatures features)
will create a bootstrapper with only the default features you specify.CreateDefaultWithout(string[] args, DefaultFeatures features)
will create a bootstrapper with all the default features except the ones that you specify.
The default behavior of the bootstrapper is controlled by DefaultFeatures
flags:
None
: No default features will be added.BootstrapperConfigurators
: Adds all implementations ofIConfigurator<Bootstrapper>
andIConfigurator<IBootstrapper>
(see configurators).Logging
: Adds default logging providers such as the console logger.Settings
: Sets default values for certain settings.EnvironmentVariables
: Adds all environment variables as settings.ConfigurationFiles
: Adds support for configuration files.BuildCommands
: Adds the defaultpipelines
anddeploy
commands as well as allICommand
implementations.CustomCommands
: Adds allICommand
implementations without also adding thepipelines
anddeploy
commands.Shortcodes
: Adds all shortcodes.Namespaces
: Adds all namespaces from all referenced assemblies to theNamespaces
collection in the engine.Pipelines
: Adds all pipelines in the entry assembly.All
: Configures all default features.
W D Avoiding Default Behavior in Statiq Web
When you create a bootstrapper using the Bootstrapper.Factory.CreateWeb(args)
extension method, it implies that the default bootstrapper behavior should be included and automatically configures all default behavior for Statiq Web. If you'd rather have more control over bootstrapper default behavior, you can use the AddWeb()
extension method after creating a standard bootstrapper with something like .CreateDefaultWithout()
instead.
For example, this creates a bootstrapper without adding pipelines from the entry assembly automatically:
using System;
using System.Threading.Tasks;
using Statiq.App;
using Statiq.Web;
namespace MySite
{
public class Program
{
public static async Task<int> Main(string[] args) =>
await Bootstrapper
.Factory
.CreateDefaultWithout(args, DefaultFeatures.Pipelines)
.AddWeb()
.RunAsync();
}
}
Child Pages
Configurators
Configurators are classes that can manipulate the engine, bootstrapper, and other items at startup.
Specifying Settings
You can use the bootstrapper to specify settings, either from various sources like configuration files and environment variables, or by using fluent methods.
Commands
The command-line commands are fully configurable which allows you to extend or replace the behavior of your generator with whatever you want.
Registering Services
Statiq uses a dependency injection container to provide certain services and you can register your own services and use them in your pipelines and modules.
Adding Pipelines
By default the bootstrapper will automatically add all pipelines by type in the entry assembly via reflection, but you can also use it to add or define new pipelines.
Modifying Pipelines
Sometimes you may want to modify an existing pipeline. This is particularly helpful in cases like Statiq Web where you have an existing set of pipelines that are defined by someone else and want to tweak their behavior by adding, removing, or changing the modules they contain.