예제 #1
0
        public static IServiceCollection AddNetCoreStackJobServer(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 });
            }

            services.AddSingleton(opts);

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

            services.AddSingleton(assemblyOptions);

            services.TryAdd(ServiceDescriptor.Singleton <IJobStorage, DefaultJobStorage>());

            return(services);
        }
예제 #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;
        }