Exemple #1
0
 /// <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));
        }
Exemple #3
0
 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)));
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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()));
        }
Exemple #8
0
 /// <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);
Exemple #14
0
        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."
                });
            }
        }
Exemple #15
0
            public override JobActivatorScope BeginScope(JobActivatorContext context)
            {
                var scope = AsyncScopedLifestyle.BeginScope(_container);

                return(new SimpleInjectorScope(_container, scope));
            }
Exemple #16
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new WindsorJobActivatorScope(this));
 }
Exemple #17
0
 public ServiceProviderScope(IServiceProvider serviceProvider, JobActivatorContext context)
 {
     _context = context;
     _scope   = serviceProvider.CreateScope();
 }
Exemple #18
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new ServiceProviderScope(_serviceProvider, context));
 }
Exemple #19
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     //some code here
     return(base.BeginScope(context));
 }
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new HangfireIocJobActivatorScope(this, _serviceProvider));
 }
Exemple #21
0
 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);
 }
Exemple #25
0
 /// <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()));
 }
Exemple #26
0
        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"))
 {
 }
Exemple #30
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new HangfireJobActivatorScope(_serviceScopeFactory.CreateScope()));
 }
Exemple #31
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new AutofacScope(_useTaggedLifetimeScope
         ? _lifetimeScope.BeginLifetimeScope(LifetimeScopeTag)
         : _lifetimeScope.BeginLifetimeScope()));
 }
Exemple #32
0
 public override JobActivatorScope BeginScope(JobActivatorContext context)
 {
     return(new UnityScope(container.CreateChildContainer()));
 }