Configuring Jasper Applications Edit on GitHub


While this topic dives into some of the more general options available in JasperRegistry, check out these topics for deeper discussions of setting up Jasper applications:

Service Name

By default, Jasper derives a descriptive ServiceName for your application by taking the class name of your JasperRegistry and stripping off any "JasperRegistry" or "Registry" suffix. For diagnostic purposes and for the dynamic subscriptions and service discovery, you may want to override the service name like so:


public class CustomServiceRegistry : JasperRegistry
{
    public CustomServiceRegistry()
    {
        // The derived default would be "CustomService"
        ServiceName = "My Custom Service";


    }
}

Environment Name

Jasper exposes the ASP.Net Core Environment name with this usage:


public class EnvironmentNameRegistry : JasperRegistry
{
    public EnvironmentNameRegistry()
    {
        // By default, this is delegating to ASP.Net Core
        if (EnvironmentName == "Development")
        {
            Features.Include<DiagnosticServer>();
        }

        // Override the Environment
        EnvironmentName = "Production";

        // which is just a shortcut for:
        Http.UseEnvironment("Production");

    }
}

You can use the EnvironmentName property within the constructor function of your JasperRegistry to do conditional configuration based on environment.

Service Registrations

Note! Jasper was conceived and designed in no small part to reduce the role of an IoC container at runtime, but "much, much less" is still more than "none."

Like most application frameworks in .Net, Jasper uses an IoC container to do basic composition within its runtime pipeline. You can add your own registrations to the application container directly in your JasperRegistry:


public class MyJasperApp : JasperRegistry
{
    public MyJasperApp()
    {
        // Adding services to the underlying container via
        // the ASP.Net Core DI abstractions
        Services.AddService<ISecurityService, MySecurityService>();

        // or via idiomatic StructureMap
        Services.For<ISecurityService>().Use<MySecurityService>();
    }
}

See IoC Container Integration for a lot more information about how Jasper uses an IoC container.

Adding Extensions

Jasper comes with its own extensibility model based on an interface called IJasperExtension. A custom extension might look something like this:


public class CustomJasperExtension : IJasperExtension
{
    public void Configure(JasperRegistry registry)
    {
        // apply alterations
    }

    public int Threshold { get; set; } = 10;
}

The syntax in JasperRegistry to apply that extension is shown below:


public class AppWithExtensions : JasperRegistry
{
    public AppWithExtensions()
    {
        // as is
        Include<CustomJasperExtension>();

        // or
        Include(new CustomJasperExtension());

        // or use the extension with customizations
        Include<CustomJasperExtension>(_ =>
        {
            _.Threshold = 20;
        });
    }
}

See Extensions for more information on building, using, and auto-discovering Jasper extensions.

Customizing Code Generation

TODO(Use the Marten transactional behavior sample?)