Ejemplo n.º 1
0
        public static IServiceCollection AddJobs(this IServiceCollection services, Action <JobBuilderOptions> setup)
        {
            services.AddMemoryCache();
            services.AddOptions();

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (setup == null)
            {
                throw new ArgumentNullException(nameof(setup));
            }

            services.AddSingleton <BackgroundJobServerMarkerService>();

            var opts = new JobBuilderOptions();

            setup?.Invoke(opts);
            foreach (var item in opts.JobList)
            {
                var type            = item.Type;
                var genericRegistry = registryDelegate.MakeGenericMethod(type);
                genericRegistry.Invoke(null, new object[] { services, type });

                if (item.ThrottlerType != null)
                {
                    services.AddTransient(item.ThrottlerType);
                }
            }

            services.AddSingleton(opts);

            var assemblies      = opts.JobList.Select(j => j.GetType().Assembly).Distinct().ToList();
            var assemblyOptions = new AssemblyOptions(assemblies);

            services.AddSingleton(assemblyOptions);

            return(services);
        }
Ejemplo n.º 2
0
        public RedisStorage(IOptions <RedisStorageOptions> optionsAccessor, AssemblyOptions assemblyOptions)
        {
            if (optionsAccessor == null)
            {
                throw new ArgumentNullException(nameof(optionsAccessor));
            }

            if (assemblyOptions == null)
            {
                throw new ArgumentNullException(nameof(assemblyOptions));
            }


            _options = optionsAccessor.Value;

            if (string.IsNullOrEmpty(_options.InstanceName))
            {
                throw new ArgumentNullException(nameof(_options.InstanceName));
            }

            _instance    = _options.InstanceName + ":";
            AssemblyList = assemblyOptions.AssemblyList;
        }