public static void AddWhenDoJob(this IServiceCollection services, Action <WhenDoConfiguration> setupAction = null)
        {
            if (services.Any(x => x.ServiceType == typeof(WhenDoConfiguration)))
            {
                throw new InvalidOperationException("WhenDoJob services already registered");
            }

            var config = new WhenDoConfiguration();

            setupAction?.Invoke(config);

            services.AddSingleton <IServiceCollection>(services); //TODO: remove this
            services.AddTransient <JobStorage>(config.HangfireStorageFactory);
            services.AddSingleton <WhenDoConfiguration>(config);
            services.AddSingleton <IWhenDoQueueProvider>(config.QueueFactory);
            services.AddTransient <IWhenDoJobManager, WhenDoJobManager>();
            services.AddSingleton <IWhenDoJobExecutionManager, WhenDoJobExecutionManager>();
            services.AddTransient <IBackgroundJobClient, BackgroundJobClient>();
            services.AddTransient <IWhenDoJobExecutionManager, WhenDoJobExecutionManager>();
            services.AddSingleton <IWhenDoEngine, WhenDoEngine>();
            services.AddSingleton <IWhenDoRepository <IWhenDoJob> >(config.JobRepositoryFactory);
            services.AddTransient <IDateTimeProvider, DateTimeProvider>();
            services.AddTransient <IWhenDoCommandExecutor, WhenDoCommandExecutor>();
            services.AddSingleton <IWhenDoRegistry, WhenDoRegistry>();
        }
Example #2
0
        public WhenDoEngine(IWhenDoQueueProvider queue, IServiceProvider serviceProvider, IWhenDoJobExecutionManager jobExecutionManager,
                            ILogger <WhenDoEngine> logger, IWhenDoRegistry registry, WhenDoConfiguration config, JobStorage hangfireStorage, IWhenDoJobManager jobManager)
        {
            this.queue               = queue;
            this.logger              = logger;
            this.serviceProvider     = serviceProvider;
            this.registry            = registry;
            this.config              = config;
            this.hangfireStorage     = hangfireStorage;
            this.jobExecutionManager = jobExecutionManager;
            this.jobManager          = jobManager;

            RegisterExpressionProviders(); //TODO: make automatic registration configurable
        }