Bootstrapper

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 of IConfigurator<Bootstrapper> and IConfigurator<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 default pipelines and deploy commands as well as all ICommand implementations.
  • CustomCommands: Adds all ICommand implementations without also adding the pipelines and deploy commands.
  • Shortcodes: Adds all shortcodes.
  • Namespaces: Adds all namespaces from all referenced assemblies to the Namespaces collection in the engine.
  • Pipelines: Adds all pipelines in the entry assembly.
  • All: Configures all default features.

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 file 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.