我有一个IRemoteCaller
,它是由HttpCaller
实现的,它需要HttpCallerOptions
进行实例化,如下所示,
public class HttpCaller : IRemoteCaller {
private HttpCallerOptions _options;
public HttpCaller(IOptions<HttpCallerOptions> options) {
_options = options.Value;
}
}
现在我有一个服务RulesService
用IRulesService
实现RulesServiceOptions
,并且依赖于IRemoteCaller
,如下所示,
public class RuleService : IRulesService {
private RulesServiceOptions _options;
private IRemoteCaller _svc;
public RulesService (IOptions<RulesServiceOptions> options, IRemoteCaller svc) {
_options = options.Value;
_svc = svc;
}
我的创业公司将注册我的服务并按如下所示配置选项,
public void ConfigureServices(IServiceCollection services) {
services.Configure<HttpCallerOptions>(o => o.SomeProps); //Default options
services.AddTransient<IRemoteCaller, HttpCaller>();
services.Configure<HttpcallerOptions>(
o => o.RuleServiceSpecificHttpOptions); //Specific options to the RuleService
services.Configure<RulesServiceOptions>(o => o.RuleServiceOptions);
services.Configure<IRulesService, RuleService>();
}
现在,我为HttpCaller
有两个命名选项,我想在RuleService
实例中注入HttpCaller
实例时注入特定于RuleService
的选项。当我不在RuleService
中使用它时,应为HttpCaller
选项配置Default
实例。
如何实现?