Bootstrapping Edit on GitHub


To configure and bootstrap a Jasper application, you are primarily interacting with just a handful of types:

  1. JasperRuntime - this manages the lifecycle of a Jasper application from bootstrapping to cleanly shutting down the application and releasing resources. It also exposes the underlying IoC container for the application and several members that just provide information about the running application
  2. JasperRegistry - this class is used to configure all the options of a Jasper application
  3. JasperAgent - a static helper for bootstrapping and managing a JasperRuntime from a console application. See Jasper in Console Applications for more information
  4. IWebHostBuilder.UseJasper() or IApplicationBuilder.AddJasper() - extension methods provided to add Jasper to an ASP.Net Core application. See Adding Jasper to an ASP.Net Core Application for more information.

If you do not need to override or add to any of Jasper's default configuration, you can happily bootstrap a JasperRuntime like this:


using (var runtime = JasperRuntime.Basic())
{
    // do stuff
}

Which is just syntactical sugar for:


using (var runtime = JasperRuntime.For(new JasperRegistry()))
{
    // do stuff
}

This option might be enough to do some useful things with Jasper as a command executor at the least, but more likely you'll want to add other elements to your system like additional services to the underlying IoC container, messaging channels, or ASP.Net Core middleware.

All configuration and set up of Jasper starts with the JasperRegistry class. Typically you would subclass JasperRegistry, but if you have only minimal configuration needs, you might bootstrap like this:


using (var runtime = JasperRuntime.For(_ =>
{
    _.Channels.ListenForMessagesFrom("jasper://localhost:2001");
}))
{
    // do stuff
}

More likely though is that you will opt to define your application with a custom JasperRegistry:


public class MyJasperApp : JasperRegistry
{
    public MyJasperApp()
    {
        ServiceName = "My Jasper App";

        Configuration.AddEnvironmentVariables();

        Channels.ListenForMessagesFrom("lq.tcp://localhost:2111/incoming");
    }
}

And then use that to bootstrap your application:


using (var runtime = JasperRuntime.For<MyJasperApp>())
{
    // do stuff
}

// or

using (var runtime = JasperRuntime.For(new MyJasperApp()))
{
    // do stuff
}

See also: