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 custom JasperRegistry and stripping off any "JasperRegistry" or "Registry" suffix. If you are not using a custom JasperRegistry, Jasper will use the main application assembly name as the service name. For diagnostic purposes 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";
    }
}

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 any combination of:

  1. The Startup.ConfigureServices() method. Use this mechanism if you need to do conditional registrations based on the hosting environment. I.e., apply this service if in "Testing" or this other one if in "Development."
  2. Using the IWebHostBuilder.ConfigureServices() extension method
  3. With JasperRegistry.Services for Lamar-centric registrations (which also supports the ASP.Net Core service registrations as well).

But, the Jasper team strongly recommends that you make all your service registrations in one place as much as possible for easier debugging later.

Using your JasperRegistry:


public class MyJasperApp : JasperRegistry
{
    public MyJasperApp()
    {
        // Adding services to the underlying container via
        // the ASP.Net Core DI abstractions
        Services.AddTransient<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 because it is a little bit different than other .Net frameworks.

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 int Threshold { get; set; } = 10;

    public void Configure(JasperRegistry registry)
    {
        // apply alterations
    }
}

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.