/// <summary> /// 开始作用域 /// </summary> /// <param name="context">上下文</param> public override JobActivatorScope BeginScope(JobActivatorContext context) { if (_serviceResolver == null) { return(new MsdiScope(_serviceProvider.CreateScope())); } return(new AspectCoreScope(_serviceResolver.CreateScope())); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { var scope = _serviceScopeFactory.BeginLifetimeScope(); var tenantService = scope.Resolve <ITenantService>(); tenantService.SetTenantByIdAsync(_tenantId); return(new AspNetCoreMultiTenantJobActivatorScope(scope)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { if (_lifestyle == null || _lifestyle != Lifestyle.Scoped) { return(new SimpleInjectorScope(_container, SimpleInjector.Lifestyles.AsyncScopedLifestyle.BeginScope(_container))); } return(new SimpleInjectorScope(_container, new SimpleInjector.Lifestyles.AsyncScopedLifestyle().GetCurrentScope(_container))); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { if (lifestyle == null || lifestyle != Lifestyle.Scoped) { return(new SimpleInjectorScope(container, AsyncScopedLifestyle.BeginScope(container))); } return(new SimpleInjectorScope(container, Lifestyle.Scoped.GetCurrentScope(container))); }
/// <summary> /// 开始一个生命周期作用域 /// </summary> /// <param name="context"></param> /// <returns></returns> public override JobActivatorScope BeginScope(JobActivatorContext context) { ILifetimeScope lifetimeScope = _useTaggedLifetimeScope ? _lifetimeScope.BeginLifetimeScope(LifetimeScopeTag) : _lifetimeScope.BeginLifetimeScope(); JobActivatorScope scope = new AutofacJobActivatorScope(lifetimeScope); CallContext.LogicalSetData(LifetimeScopeKey, scope); return(scope); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { var retorno = base.BeginScope(context); var param = context.GetJobParameter <object>("HangfireContext"); var contextProvider = retorno.Resolve(typeof(IHangfireContextProvider)) as IHangfireContextProvider; contextProvider.SetContext(param); return(retorno); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { if (_lifestyle == null) { return(new SimpleInjectorScope(_container, _container.BeginExecutionContextScope())); } else if (_lifestyle == Lifestyle.Scoped) { return(new SimpleInjectorScope(_container, ThreadScopedLifestyle.BeginScope(_container))); } return(new SimpleInjectorScope(_container, _container.GetCurrentExecutionContextScope())); }
/// <inheritdoc /> public override JobActivatorScope BeginScope(JobActivatorContext context) => new StashboxJobActivatorScope(this.container.BeginScope());
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new NestedContainerJobActivatorScope(container)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return new AspNetCoreJobActivatorScope(_serviceScopeFactory.CreateScope()); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(CreateScope()); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { var scope = _mtc.GetTenantScope(_tenantId).BeginLifetimeScope(); return(new AspNetCoreMultiTenantJobActivatorScope(scope)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) => new MyScope(ServiceProvider.CreateScope().ServiceProvider, context);
private IState PerformJob(BackgroundProcessContext context, IStorageConnection connection, string jobId) { try { var jobData = connection.GetJobData(jobId); if (jobData == null) { // Job expired just after moving to a processing state. This is an // unreal scenario, but shit happens. Returning null instead of throwing // an exception and rescuing from en-queueing a poisoned jobId back // to a queue. return(null); } jobData.EnsureLoaded(); var backgroundJob = new BackgroundJob(jobId, jobData.Job, jobData.CreatedAt); var jobToken = new ServerJobCancellationToken(connection, jobId, context.ServerId, _workerId, context.CancellationToken); var jobActivatorContext = new JobActivatorContext(connection, backgroundJob, jobToken); var scope = _activator.BeginScope(jobActivatorContext); if (scope != null) { using (scope) { var performContext = new PerformContext(connection, backgroundJob, jobToken, _profiler, scope); var latency = (DateTime.UtcNow - jobData.CreatedAt).TotalMilliseconds; var duration = Stopwatch.StartNew(); var result = _performer.Perform(performContext); duration.Stop(); return(new SucceededState(result, (long)latency, duration.ElapsedMilliseconds)); } } else { if (jobActivatorContext.ReEnqueueAt.HasValue) { return(new ScheduledState(jobActivatorContext.ReEnqueueAt.Value)); } else { return(new FailedState(new InvalidOperationException("Scope could not be started"))); } } } catch (JobAbortedException) { // Background job performance was aborted due to a // state change, so it's idenfifier should be removed // from a queue. return(null); } catch (JobPerformanceException ex) { return(new FailedState(ex.InnerException) { Reason = ex.Message }); } catch (Exception ex) { if (ex is OperationCanceledException && context.IsShutdownRequested) { throw; } return(new FailedState(ex) { Reason = "An exception occurred during processing of a background job." }); } }
public override JobActivatorScope BeginScope(JobActivatorContext context) { var scope = AsyncScopedLifestyle.BeginScope(_container); return(new SimpleInjectorScope(_container, scope)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new WindsorJobActivatorScope(this)); }
public ServiceProviderScope(IServiceProvider serviceProvider, JobActivatorContext context) { _context = context; _scope = serviceProvider.CreateScope(); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new ServiceProviderScope(_serviceProvider, context)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { //some code here return(base.BeginScope(context)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new HangfireIocJobActivatorScope(this, _serviceProvider)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new DefaultJobActivatorScope(this)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new AutofacScope(this.lifetimeScope.BeginLifetimeScope(LifetimeScopeTag))); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new HangfireIocJobActivatorScope(this, _iocResolver)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return new HangfireIocJobActivatorScope(this, _iocResolver); }
/// <inheritdoc /> /// <summary> /// Begin a new job activation scope using a nested container /// </summary> /// <param name="context">Job activator context</param> /// <returns>A new job activation scope</returns> public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new LamarDependencyScope(this.container.GetNestedContainer())); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { var scope = _serviceProvider.CreateScope(); return(new ExtensionsScope(_serviceProvider, scope)); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new ServiceScopeDependencyScope(_serviceProvider.CreateScope())); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { Console.WriteLine("BeginScope"); return(new NinjectScope(_kernel, _clients)); }
public MyScope(IServiceProvider sp, JobActivatorContext context) : this(sp, int.Parse(context.BackgroundJob.Id), context.GetJobParameter <string>("RecurringJobId")) { }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new HangfireJobActivatorScope(_serviceScopeFactory.CreateScope())); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new AutofacScope(_useTaggedLifetimeScope ? _lifetimeScope.BeginLifetimeScope(LifetimeScopeTag) : _lifetimeScope.BeginLifetimeScope())); }
public override JobActivatorScope BeginScope(JobActivatorContext context) { return(new UnityScope(container.CreateChildContainer())); }