Hangfire background job activator based on the Lamar IoC container
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Hangfire.Lamar
test/Hangfire.Lamar.Test
.gitattributes
.gitignore
.travis.yml
Hangfire.Lamar.sln
Hangfire.Lamar.sln.DotSettings
LICENSE
README.md
appveyor.yml
build.cmd
build.sh

README.md

Hangfire.Lamar

Windows Build Status Linux Build status NuGet

This package provides Lamar support for Hangfire, allowing nested Lamar containers to resolve job type instances and their dependencies, and to manage the lifetime of resolved instances.

Getting started

Install the Hangfire.Lamar package from NuGet:

Install-Package Hangfire.Lamar

To configure Hangfire to use Lamar, configure your container and call the IGlobalConfiguration extension method, UseLamarActivator:

var container = new Container();
// container.Configure...

GlobalConfiguration.Configuration.UseLamarActivator(container);

After configuration, when jobs are started a Lamar-based implementation of the JobActivator class is used to resolve job type instances and all of their dependencies.

Object Lifecycles

Hangfire.Lamar doesn't rely on a specific object lifecycle - you can configure your dependencies as Singleton, Scoped or Transient as normal.

Hangfire.Lamar creates a nested container for each job execution, so using Scoped will scope dependency lifetimes to that of the job.

var container = new Container(c =>
  c.For<IRepository>().Use<GenericRepository>().Scoped();
);

The nested container is disposed when jobs ends, and all dependencies that implement the IDisposable interface are also automatically disposed (Singleton scoped instances are of course an exception, and are only disposed when the root container is disposed).