Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

BrighterCommand/Paramore.Brighter.Extensions

Repository files navigation

This Repo has now been merged into the main Brighter Repo Brighter Work will continue there and please raise issues there too. Thanks!

.NET Core Extensions for Brighter.

  • Dependency Injection integration for Brighter
  • Dependency Injection integration for Service Activator
  • IHostedService for background tasks

Build status

NuGet

1. Paramore.Brighter.Extensions.DependencyInjection

Usage

In your ConfigureServices method, use AddBrighter to add Brighter to the container.

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Add Brighter.
    services.AddBrighter()
        .AsyncHandlersFromAssemblies(typeof(CreateFooHandler).Assembly);

    // Add framework services.
    services.AddMvc();
}

You can customize Brighter by configuring BrighterOptions:

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
    // Add Brighter.
    services.AddBrighter(opts =>
        {
            opts.RequestContextFactory = new MyCustomRequestContextFactory();
            opts.PolicyRegistry = new MyCustomPolicies();
            opts.MessagingConfiguration = new MyTaskQueues();
        })
    .AsyncHandlersFromAssemblies(typeof(CreateFooHandler).Assembly);

    // Add framework services.
    services.AddMvc();
}

2. Paramore.Brighter.ServiceActivator.Extensions.DependencyInjection

Usage

In your ConfigureServices method, use AddServiceActivator to add Service Activator to the container.

public void ConfigureServices(IServiceCollection services)
{
    services.AddServiceActivator(options =>
        {
            options.Connections = connections;
            options.ChannelFactory = new InputChannelFactory(rmqMessageConsumerFactory);
        })
        .MapperRegistryFromAssemblies(typeof(GreetingEventHandler).Assembly)
        .HandlersFromAssemblies(typeof(GreetingEventHandler).Assembly);
}

3. Paramore.Brighter.ServiceActivator.Extensions.Hosting

Extension to easly implement background tasks and scheduled jobs using IHostedService see Implement background tasks

Usage

In your ConfigureServices method, use AddHostedService<ServiceActivatorHostedService>() to add ServiceActivatorHostedService to the container.

public void ConfigureServices(IServiceCollection services)
{
    services.AddHostedService<ServiceActivatorHostedService>();
}