Giter VIP home page Giter VIP logo

hangfire.unity4's Introduction

Hangfire.Unity4

Build status NuGet

This project is based on the Hangfire.Unity project with 2 chnages

  • Hangfire.Unity works fine for Unity v5+ but due to namespace changes you can't use it for Unity v4. This package (Hangfire.Unity4) works with old namespace of unity which is Microsoft.Practices.Unity
  • This package also have a helper class for lifetime management called PerRequestOrHierarchicalLifeTimeManager which if you don't have HttpContext available, it will offer HierarchicalLifetimeManager instead of PerRequestLifetimeManager you can use this to in RegisterTypes method to avoid Resolve exception
public static void RegisterTypes(IUnityContainer container)
{
    container.RegisterType<IMyService, MyService>(new PerRequestOrHierarchicalLifeTimeManager());
}

Hangfire background job activator based on Unity IoC Container. It allows you to use instance methods of classes that define parametrized constructors:

public class EmailService
{
	private DbContext _context;
    private IEmailSender _sender;
	
	public EmailService(DbContext context, IEmailSender sender)
	{
		_context = context;
		_sender = sender;
	}
	
	public void Send(int userId, string message)
	{
		var user = _context.Users.Get(userId);
		_sender.Send(user.Email, message);
	}
}	

// Somewhere in the code
BackgroundJob.Enqueue<EmailService>(x => x.Send(1, "Hello, world!"));

Improve the testability of your jobs without static factories!

Installation

Hangfire.Unity4 is available as a NuGet Package. Type the following command into NuGet Package Manager Console window to install it:

Install-Package Hangfire.Unity4

Usage

The package provides an extension method for OWIN bootstrapper:

app.UseHangfire(config =>
{
    var container = new UnityContainer();
	// Setup your unity container
	
	// Use it with Hangfire
    config.UseUnityActivator(container);
});

In order to use the library outside of web application, set the static JobActivator.Current property:

var container = new UnityContainer();
JobActivator.Current = new UnityJobActivator(container);

hangfire.unity4's People

Contributors

hameds avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

0xrustlang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.