Exemple #1
0
        public static IServiceCollection AddQueuing(
            this IServiceCollection services,
            Action <QueuingBuilder> queuingBuilder)
        {
            services.AddHangfire((sp, configuration) =>
            {
                configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseActivator(sp.GetService <MiruJobActivator>());

                var builder = new QueuingBuilder(sp, configuration);

                queuingBuilder.Invoke(builder);
            });

            services.AddTransient <MiruJobActivator>();

            services.AddTransient(sp => new BackgroundJobServer(
                                      new BackgroundJobServerOptions(),
                                      sp.GetService <JobStorage>()));

            return(services.AddSingleton <Jobs>());
        }
        public static void UseLiteDb(this QueuingBuilder builder)
        {
            var storage = builder.ServiceProvider.GetService <Storage>();
            var env     = builder.ServiceProvider.GetService <IHostEnvironment>();

            builder.Configuration.UseLiteDbStorage(storage.MakePath("db", $"Queue_{env.EnvironmentName}.db"));
        }