我正在使用 .Net Core 后台服务连接到 Kafka 并将消息保存到 SQL Server。我的项目结构如下所示:

Entity Framework在基础设施依赖项中,我使用IConfiguration configuration从 WorkerProgram.cs文件传递的以下代码进行注册services.AddInfrastructure(configuration):
namespace JS.Svf.BackgroundServices.Infrastructure
{
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
// Add all the dependencies required by Azure Functions.
// From Infrastructure
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
services.AddTransient<IApplicationDbContext>(provider => provider.GetRequiredService<ApplicationDbContext>());
services.AddTransient<IProductRepository, ProductRepository>();
services.AddTransient<ISupplierRepository, SupplierRepository>();
return services;
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行后台服务后出现以下错误:
Cannot consume scoped service 'ApplicationDbContext' from singleton 'Microsoft.Extensions.Hosting.IHostedService'
通过参考,我知道我们需要使用IServiceScopeFactory,但我对如何在当前结构中使用它有点无能为力。请指教。
该存储库使用ApplicationDbContext …
我正在使用 Azure Durable Functions .Net Core。
[FunctionName("Calculate")]
public async Task RunOrchestrator(
[OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
{
await context.CallActivityAsync<object>(FuncConstants.Cal1, null);
await context.CallActivityAsync<object>(FuncConstants.Cal2, null);
await context.CallActivityAsync<object>(FuncConstants.Cal3, null);
await context.CallActivityAsync<object>(FuncConstants.Cal4, null);
await context.CallActivityAsync<object>(FuncConstants.Cal5, null);
await context.CallActivityAsync<object>(FuncConstants.Cal6, null);
await context.CallActivityAsync<object>(FuncConstants.Cal7, null);
await context.CallActivityAsync<object>(FuncConstants.Cal8, null);
await context.CallActivityAsync<object>(FuncConstants.Cal9, null);
}
[FunctionName("Starter_Calculation")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
string instanceId = await starter.StartNewAsync("Calculate", null);
return starter.CreateCheckStatusResponse(req, instanceId);
}
Run Code Online (Sandbox Code Playgroud)
这里,每个函数需要超过 5-6 个小时来执行一些逻辑计算(算术运算),因为它们处理超过 27-3000 万条数据库记录。
我收到第一个函数本身的错误为 "Timeout value …
timeoutexception long-running-processes azure-durable-functions
我在 Angular-9 应用程序中有 3 个组件,如下所示:
组件1
<div>
// I have a button here with Click Event.
</div>
Run Code Online (Sandbox Code Playgroud)
组件2
<div>
// I have a Grid here.
</div>
In a class file I'm getting Data and Binding Grid using ngOnInit() method.
Run Code Online (Sandbox Code Playgroud)
我在第三个组件中使用这两个组件,如下所示:
组件 3
<div id='third-component'>
<component-one></component-one>
<component-two></component-two>
</div>
Run Code Online (Sandbox Code Playgroud)
我想通过单击Component1中的按钮刷新Component2数据。这个怎么做?
我在我的模型中使用远程属性来检查重复的页面标题如下
public class Page
{
[Remote("CheckDuplicate", "Page", ErrorMessage = "Title already taken")]
public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,我将根据" 检查 "结果返回JsonResult数据,如下所示:
public JsonResult CheckDuplicate(string Title)
{
var result = db.Pages.Where(a => a.Title == Title).Count() == 0;
return Json(result, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
这在Create动作中工作正常,但问题是,它限制了我编辑现有页面,因为它正在检查相同的查询.
如何解决这个问题呢?请建议我