public ControllerX(IServiceA serviceA, IServiceB serviceB, INumberService numberService) { _n = numberService.GetNumber(); Console.WriteLine($"ctor {nameof(ControllerX)}, {_n}"); _serviceA = serviceA; _serviceB = serviceB; }
//通过构造函数注入INumberService public ServiceA(INumberService numberService) { //获取数码,并赋值给私有变量_n _n = numberService.GetNumber(); //在对象构建时输出_n--观察对象生命周期 Console.WriteLine($"ctor {nameof(ServiceA)}, {_n}"); }
public MainWindowViewModel(INumberService numberService) { _numberService = numberService; GetNumberCommand = ReactiveCommand.Create(() => { Number = _numberService.GetNumber(); }); }
public ServiceA(INumberService numberService) { _n = numberService.GetNumber(); Console.WriteLine($"ctor {nameof(ServiceA)}, {_n}"); }
public ServiceA(INumberService numberService, IOptions <ConfigurationA> options) { _mode = options.Value.Mode; _n = numberService.GetNumber(); Console.WriteLine($"ctor {nameof(ServiceA)}, {_n}"); }