本文整理汇总了C#中IServiceCollection.AddHangfire方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddHangfire方法的具体用法?C# IServiceCollection.AddHangfire怎么用?C# IServiceCollection.AddHangfire使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddHangfire方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ImperaContext>(options =>
{
string connection = Configuration["DBConnection"];
options.UseSqlServer(connection, b=> b.MigrationsAssembly("ImperaPlus.Web"));
});
services.AddCors(opts => opts.AddPolicy(
opts.DefaultPolicyName,
new CorsPolicy
{
SupportsCredentials = false
}));
// Auth
services.AddIdentity<Domain.User, IdentityRole>(options =>
{
options.User.RequireUniqueEmail = true;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireDigit = false;
options.SignIn.RequireConfirmedEmail = true;
options.SignIn.RequireConfirmedPhoneNumber = false;
if (this.Environment.IsDevelopment())
{
options.SignIn.RequireConfirmedEmail = false;
}
})
.AddEntityFrameworkStores<ImperaContext>()
.AddDefaultTokenProviders();
var openIddict = services.AddOpenIddict<ImperaContext>()
.EnableTokenEndpoint("/api/Account/Token")
.AllowPasswordFlow()
.AllowRefreshTokenFlow();
if (this.Environment.IsDevelopment())
{
openIddict
// During development, you can disable the HTTPS requirement.
.DisableHttpsRequirement()
.AddEphemeralSigningKey();
}
// Swagger
//services.AddTransient<IApiDescriptionGroupCollectionProvider, ApiDescriptionGroupCollectionProvider>();
services.AddSwaggerGen(options =>
{
options.OperationFilter<FormFilter>();
options.DescribeStringEnumsInCamelCase();
options.IncludeXmlComments(AppDomain.CurrentDomain.BaseDirectory + "ImperaPlus.Web.xml");
});
services.AddMvc(config =>
{
config.Filters.Add(new CheckModelForNull());
})
.AddJsonOptions(opt =>
{
opt.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
opt.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
opt.SerializerSettings.Converters.Add(new StringEnumConverter
{
CamelCaseText = false,
AllowIntegerValues = true
});
opt.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
});
// Hangire
services.AddHangfire(x =>
x.UseNLogLogProvider()
.UseFilter(new JobExpirationTimeAttribute())
.UseSqlServerStorage(Configuration["DBConnection"]));
services.AddSingleton(_ => new JsonSerializer
{
DateTimeZoneHandling = DateTimeZoneHandling.Utc,
DateFormatHandling = DateFormatHandling.IsoDateFormat,
ContractResolver = new SignalRContractResolver()
});
services.AddSignalR(options => options.Hubs.EnableDetailedErrors = true);
return this.RegisterDependencies(services);
}
示例2: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
Console.WriteLine(_environment.WebRootPath);
var dbFile = "OkMidnight.db";
if(!String.IsNullOrEmpty(_environment.WebRootPath))
dbFile = System.IO.Path.Combine(_environment.WebRootPath, "..", dbFile);
services.AddIdentity<Identity, Role>()
.AddUserStore<EmptyUserStore>()
.AddRoleStore<EmptyRoleStore>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddEntityFrameworkNpgsql()
.AddDbContext<OkMidnightDbContext>(options =>
options.UseNpgsql(_configuration["Database:ConnectionString"]));
_logger.LogInformation("Using ImageMagick in {0}", _configuration["Magick:Path"]);
services.Configure<PictureProcessorOptions>(o => o.BinaryPath = _configuration["Magick:Path"]);
services.AddTransient<IPictureProcessor, MagickPictureProcessor>();
services.AddTransient<ResizerJob>();
services.AddTransient<PictureStorageService>();
services.AddHangfire(x => x.UseStorage(new PostgreSqlStorage(_configuration["Database:ConnectionString"])));
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
// Add Hangfire to services using RavenDB Storage
// BUG: https://github.com/cady-io/hangfire-ravendb/issues/15
//services.AddHangfire(t => t.UseRavenStorage(Configuration["ConnectionStrings:RavenDebug"]));
services.AddHangfire(t => t.UseRavenStorage(Configuration["ConnectionStrings:RavenDebugUrl"], Configuration["ConnectionStrings:RavenDebugDatabase"]));
}
示例4: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
//Add CORS support.
// Must be first to avoid OPTIONS issues when calling from Angular/Browser
var corsBuilder = new CorsPolicyBuilder();
corsBuilder.AllowAnyHeader();
corsBuilder.AllowAnyMethod();
corsBuilder.AllowAnyOrigin();
corsBuilder.AllowCredentials();
services.AddCors(options =>
{
options.AddPolicy("allReady", corsBuilder.Build());
});
// Add Application Insights data collection services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
// Add Entity Framework services to the services container.
services.AddDbContext<AllReadyContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.Configure<AzureStorageSettings>(Configuration.GetSection("Data:Storage"));
services.Configure<DatabaseSettings>(Configuration.GetSection("Data:DefaultConnection"));
services.Configure<EmailSettings>(Configuration.GetSection("Email"));
services.Configure<SampleDataSettings>(Configuration.GetSection("SampleData"));
services.Configure<GeneralSettings>(Configuration.GetSection("General"));
services.Configure<TwitterAuthenticationSettings>(Configuration.GetSection("Authentication:Twitter"));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 10;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireDigit = true;
options.Password.RequireUppercase = false;
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied");
})
.AddEntityFrameworkStores<AllReadyContext>()
.AddDefaultTokenProviders();
// Add Authorization rules for the app
services.AddAuthorization(options =>
{
options.AddPolicy("OrgAdmin", b => b.RequireClaim(Security.ClaimTypes.UserType, "OrgAdmin", "SiteAdmin"));
options.AddPolicy("SiteAdmin", b => b.RequireClaim(Security.ClaimTypes.UserType, "SiteAdmin"));
});
// Add MVC services to the services container.
// config add to get passed Angular failing on Options request when logging in.
services.AddMvc().AddJsonOptions(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver());
//Hangfire
services.AddHangfire(configuration => configuration.UseSqlServerStorage(Configuration["Data:HangfireConnection:ConnectionString"]));
// configure IoC support
var container = CreateIoCContainer(services);
return container.Resolve<IServiceProvider>();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
//Add CORS support.
// Must be first to avoid OPTIONS issues when calling from Angular/Browser
var corsBuilder = new CorsPolicyBuilder();
corsBuilder.AllowAnyHeader();
corsBuilder.AllowAnyMethod();
corsBuilder.AllowAnyOrigin();
corsBuilder.AllowCredentials();
services.AddCors(options =>
{
options.AddPolicy("allReady", corsBuilder.Build());
});
// Add Application Insights data collection services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
// Add Entity Framework services to the services container.
services.AddDbContext<AllReadyContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.Configure<AzureStorageSettings>(Configuration.GetSection("Data:Storage"));
services.Configure<DatabaseSettings>(Configuration.GetSection("Data:DefaultConnection"));
services.Configure<EmailSettings>(Configuration.GetSection("Email"));
services.Configure<SampleDataSettings>(Configuration.GetSection("SampleData"));
services.Configure<GeneralSettings>(Configuration.GetSection("General"));
services.Configure<GetASmokeAlarmApiSettings>(Configuration.GetSection("GetASmokeAlarmApiSettings"));
services.Configure<TwitterAuthenticationSettings>(Configuration.GetSection("Authentication:Twitter"));
services.Configure<MappingSettings>(Configuration.GetSection("Mapping"));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
options.Password.RequiredLength = 10;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireDigit = true;
options.Password.RequireUppercase = false;
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/Home/AccessDenied");
})
.AddEntityFrameworkStores<AllReadyContext>()
.AddDefaultTokenProviders();
// Add Authorization rules for the app
services.AddAuthorization(options =>
{
options.AddPolicy("OrgAdmin", b => b.RequireClaim(Security.ClaimTypes.UserType, "OrgAdmin", "SiteAdmin"));
options.AddPolicy("SiteAdmin", b => b.RequireClaim(Security.ClaimTypes.UserType, "SiteAdmin"));
});
services.AddLocalization();
//Currently AllReady only supports en-US culture. This forces datetime and number formats to the en-US culture regardless of local culture
var usCulture = new CultureInfo("en-US");
var supportedCultures = new[] { usCulture };
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture(usCulture, usCulture);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
// Add MVC services to the services container.
// config add to get passed Angular failing on Options request when logging in.
services.AddMvc(config =>
{
config.ModelBinderProviders.Insert(0, new AdjustToTimezoneModelBinderProvider());
})
.AddJsonOptions(options =>
options.SerializerSettings.ContractResolver = new DefaultContractResolver());
//Hangfire
services.AddHangfire(configuration => configuration.UseSqlServerStorage(Configuration["Data:HangfireConnection:ConnectionString"]));
// configure IoC support
var container = CreateIoCContainer(services);
return container.Resolve<IServiceProvider>();
}