qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-免登录深度版🔥

hangfire - 将多个hangfire项目与单个postgresql数据库一起使用,如何写代码

时间2023-05-08 20:31:29 提问来自 广东省湛江市 的网友 分类创作 浏览330
要使用单个PostgreSQL数据库与多个Hangfire项目一起使用,你需要在每个Hangfire项目中定义不同的连接字符串。 您可以使用PostgreSQL的Schema机制来组织表,以便将所有表都存储在一个数据库中,而不是将其分布到多个数据库。 此外,请注意,如果你想使用Hangfire Dashboard UI来管理所有作业和工作者(而不是单独的Dashboard实例),你可能还需要使用shared filters或强制使用特定的过滤器/视图名称。 这些都可以通过DashboardOptions对象上的Filters属性来设置。 代码如下: ```csharp // Setup Hangfire with a single Postgres database for multiple projects. GlobalConfiguration.Configuration // Global Hangfire configuration object. .UseStorage(new PostgreSqlStorage("ConnectionString1")) // First project's connection string. .UseStorage(new PostgreSqlStorage("ConnectionString2")); // Second project's connection string. // Setup the dashboard to use the same connection strings and force shared filters or views names across all projects. appBuilder.UseHangfireDashboard("/hangfiredash", new DashboardOptions { Authorization = new[] { new MyAuthorizationFilter() }, // Custom authorization filter to control access to the dashboard UI. AppPath = null, // Set this property to `null` so that the Dashboard will be at "/hangfiredash" instead of "/hangfiredash/jobs". Filters = new[] { new MyFilter() } // Use custom filters or view names for each project so that they are shared across all projects in one database instance. }); ```

不满意?免费深度重写!

免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。

上一篇 合法性是什么?合法性的类型有哪些? 下一篇 发条橙 A Clockwork Orange影评