JasperFx 0.9.0


Next

Messaging

Previous

Bootstrapping

IoC Container Integration Edit on GitHub


Note! If you're curious, in the real world Lamar is a slightly bigger town just up highway 71 from Jasper's namesake.

Jasper only supports the Lamar IoC container.

See Introducing BlueMilk: StructureMap’s Replacement & Jasper’s Special Sauce for more information on exactly how the Jasper + Lamar combination works (under the original "BlueMilk" codename that most people hated;)).

To register services in a Jasper application, use the JasperRegistry.Services root like this:


public class JasperAppWithServices : JasperRegistry
{
    public JasperAppWithServices()
    {
        // Add service registrations with the ASP.Net Core
        // DI abstractions
        Services.AddLogging();
        Services.AddSingleton(new MessageTracker());

        // or mix and match with StructureMap style
        // registrations
        Services.For(typeof(ILogger)).Use(typeof(Logger<>));
    }
}

Extensions can also register services, but Jasper will enforce a service registration precedence like this:

  1. Application registrations from your JasperRegistry.Services
  2. Extension registrations
  3. Baseline Jasper and ASP.Net Core service registrations

What this means is that registrations made in your application's JasperRegistry will always win out over extensions and the base framework.

Accessing the Raw Container

The best practice in theory states that you should never need to access the underlying IoC container in your application after the initial bootstrapping, but there's always some reason (testing?), so you can do this:


public void retrieve_the_container(JasperRuntime runtime, IWebHost host)
{
    // The root Lamar IoC container hangs directly
    // off the JasperRuntime if you're bootstrapping
    // the idiomatic Jasper way
    var container = runtime.Container;

    // Or if you are using ASP.Net Core bootstrapping,
    // the IWebHost.Services is actually the root
    // Lamar container
    var container2 = (IContainer)host.Services;
}