Exemple #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         XxlJobUtilExtensions.RunSync(async() => await StopInnerAsync(new CancellationToken()));
     }
 }
        private static void ScanDynamicJobExecutorHandler(this IServiceCollection services, ServiceLifetime lifetime)
        {
            // get all types
            var typesToRegisterAndAttr = XxlJobUtilExtensions.CollectByAttributeTypes <XxlJobHandlerAttribute>()
                                         .Where(x => x.Item1.IsClass && !x.Item1.IsAbstract).ToList();

            var types = typesToRegisterAndAttr.Select(x =>
            {
                if (x.Item2.InterfaceType == null)
                {
                    // get default
                    var interfaces = x.Item1.GetInterfaces();

                    return(x.Item1, interfaces.FirstOrDefault());
                }

                return(x.Item1, x.Item2.InterfaceType);
            });

            var typesToRegisterList = types.GroupBy(x => x.Item2, y => y).ToDictionary(x => x.Key, y => y.ToList());

            typesToRegisterAndAttr.ForEach(x => services.Add(new ServiceDescriptor(x.Item1, x.Item1, lifetime)));

            if (typesToRegisterList != null)
            {
                foreach (var typesToRegister in typesToRegisterList)
                {
                    if (typesToRegister.Value != null)
                    {
                        services.AddScopedDynamicJobHandler(typesToRegister.Key, typesToRegister.Value.Select(x => x.Item1), lifetime);
                    }
                }
            }
        }