ASP.NET Core Web API-如何解析名称' addCronJobConfigurations'在当前上下文中不存在
在ASP.NET Core-5 Web API中,我有:
startup.cs:
public void Configure(IApplicationBuilder app,
IWebHostEnvironment env,
IRecurringJobManager recurringJobManager,
IServiceProvider serviceProvider)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseHangfireDashboard();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
var branchService = serviceProvider.GetService<IAdminBranchService>();
recurringJobManager.AddOrUpdate("Post_All_Branches", () => branchService.CreateBranchAsync(), Cron.Minutely);
}
但是现在我正在使用ASP.NET Core-6 Web API。因此,对于hangfire cronjob,我创建了一个类,如下所示:
public static class CronJobExtension
{
public static void AddCronJobConfigurations(IRecurringJobManager recurringJobManager, IServiceProvider serviceProvider)
{
var branchService = serviceProvider.GetService<IAdminBranchService>();
recurringJobManager.AddOrUpdate("Post_All_Branches", () => branchService.CreateBranchAsync(), Cron.Minutely);
}
}
所以我只有program.cs。然后,我在program.cs中引用了addcronjobconfiguration。
program.cs:
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseHangfireDashboard();
AddCronJobConfigurations();
但是我有一个错误:
错误CS0103名称“ AddCronJobConfigurations”在当前上下文中不存在
我如何解决此问题?
谢谢
In ASP.NET Core-5 Web API, I have this:
Startup.cs:
public void Configure(IApplicationBuilder app,
IWebHostEnvironment env,
IRecurringJobManager recurringJobManager,
IServiceProvider serviceProvider)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseHangfireDashboard();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
var branchService = serviceProvider.GetService<IAdminBranchService>();
recurringJobManager.AddOrUpdate("Post_All_Branches", () => branchService.CreateBranchAsync(), Cron.Minutely);
}
But now I am using ASP.NET Core-6 Web API. So for the HangFire CronJob I created a class as shown here:
public static class CronJobExtension
{
public static void AddCronJobConfigurations(IRecurringJobManager recurringJobManager, IServiceProvider serviceProvider)
{
var branchService = serviceProvider.GetService<IAdminBranchService>();
recurringJobManager.AddOrUpdate("Post_All_Branches", () => branchService.CreateBranchAsync(), Cron.Minutely);
}
}
So in I only have Program.cs. Then I referenced AddCronJobConfigurations in Program.cs.
Program.cs:
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseHangfireDashboard();
AddCronJobConfigurations();
But I got this error:
Error CS0103 The name 'AddCronJobConfigurations' does not exist in the current context
How do I get this resolved?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行此操作:
或使用
此
关键字创建一个扩展方法:并以相同的方式使用它,使用略有不同的语法:
You can do this:
Or use
this
keyword to create an extension method:and use it the same way, with slightly different syntax: