//第一种方式 //public ValuesController(Func<string, IJK> serviceAccessor) //{ // this._serviceAccessor = serviceAccessor; // _serviceA = _serviceAccessor("JK1"); // _serviceB = _serviceAccessor("JK2"); //} //第二种方式 public ValuesController(IEnumerable <IJK> svs) { foreach (var sv in svs) { if (sv is JK1) { _serviceA = sv; } if (sv is JK2) { _serviceB = sv; } } }
public ValuesController(Func <string, IJK> serviceAccessor) { this._serviceAccessor = serviceAccessor; _serviceA = _serviceAccessor("JK1"); _serviceB = _serviceAccessor("JK2"); }