【发布时间】:2019-09-22 07:19:30
【问题描述】:
我在 Windows 服务中使用 EF Core 和 Autofac 上的存储库模式。
我有一项服务需要连接几十个数据库,这些数据库具有相同的架构(相同的 dbcontext)但只有不同的数据。 如何使用 Autofac 在我的服务中实现这一点?贝洛
public class ReportRepository : IReportRepository
{
private readonly ReportDbContext dbContext;
public ReportRepository(ReportDbContext dbContext)
{
this.dbContext = dbContext
}
public SomeModel GetData()
{
return dbContext.SalesData;
}
}
public class ReportService : IReportService
{
private readonly IReportRepository reportRepositoryEUServer;
public ReportService(IReportRepository reportRepositoryEUServer)
{
this.reportRepositoryEUServer = reportRepositoryEUServer
}
public SomeModelDto GenerateReport()
{
var euData = reportRepositoryEUServer.GetData();
// I need to call other servers (e.g LATAM) here and get the data and aggregate them with euData
}
}
【问题讨论】:
-
你检查过 autofac 文档中的装饰器autofaccn.readthedocs.io/en/latest/advanced/…
标签: c# .net .net-core entity-framework-core autofac