init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
47
KretaWeb/HangfireJobActivator/JobActivator.cs
Normal file
47
KretaWeb/HangfireJobActivator/JobActivator.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using Hangfire;
|
||||
using SimpleInjector;
|
||||
|
||||
namespace Kreta.Web.HangfireJobActivator
|
||||
{
|
||||
public class ContainerJobActivator : JobActivator
|
||||
{
|
||||
private readonly Container container;
|
||||
|
||||
public ContainerJobActivator(Container container)
|
||||
{
|
||||
this.container = container ?? throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
public override object ActivateJob(Type type) => this.container.GetInstance(type);
|
||||
|
||||
public override JobActivatorScope BeginScope(JobActivatorContext context)
|
||||
{
|
||||
return new InjectorScope(this.container);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class InjectorScope : JobActivatorScope
|
||||
{
|
||||
private readonly Container container;
|
||||
|
||||
public InjectorScope(Container container)
|
||||
{
|
||||
this.container = container;
|
||||
SimpleInjector.Lifestyles.AsyncScopedLifestyle.BeginScope(this.container);
|
||||
}
|
||||
|
||||
public override void DisposeScope()
|
||||
{
|
||||
Scope currentExecutionContextScope = Lifestyle.Scoped.GetCurrentScope(this.container);
|
||||
if (currentExecutionContextScope != null)
|
||||
{
|
||||
currentExecutionContextScope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override object Resolve(Type type) =>
|
||||
this.container.GetInstance(type);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue