我传给IOption<T>了我,CommandBus所以我可以从ServiceBusSetting班上得到设置.我想对我的总线进行集成测试.我不想解决它只是使用new QueueCommandBus,需要传递IOptions给它.
var services = new ServiceCollection().AddOptions();
services.Configure<ServiceBusAppSettings>(Configuration.GetSection("ServiceBus"));
var options = services.BuildServiceProvider().GetService<IOptions<ServiceBusAppSettings>>();
////Act
var commandBus = new QueueCommandBus(options);
Run Code Online (Sandbox Code Playgroud)
这工作正常,但感觉非常复杂的代码IOptions<T>从我appsetting.json的测试项目中获取.
任何线索,如果这是唯一的方式或有更好的方法?