如何使用Autofac解析依赖运行时参数的嵌套依赖项?
例如:
class OrderService : IOrderService
{
IInventoryService inventoryService;
JobConfiguration configuration;
OrderService(JobConfiguration configuration, IInventoryService inventoryService)
{
this.inventoryService = inventoryService;
this.configuration = configuration;
}
DoSomething()
{
//here I can resolve the configuration values for the SFTPClient, so I want to call the Inventory service (that relies on the ISftpClient)
}
class InventoryService : IInventoryService
{
ISftpClient sftpClient;
InventoryService(ISftpClient sftpClient)
{
this.sftpClient = sftpClient;
}
}
class SftpClient : ISftpClient
{
string host;
string username;
string password;
SftpClient(string host, string username, string password)
{
this.host = host;
this.username = username;
this.password = password.
}
}
如果我想解决IOrderService
(或将其传入另一个类),我将如何解决这个问题,因为某些依赖关系依赖于我需要从更高级别传递的配置值。在对象图中?该服务可以在对象图中很多层。
我问了this哪个问题建议使用SftpClient的工厂,但是当嵌套依赖项时,我看不出它是如何工作的。