具体来说,我在看微软的这行代码.扩展.依赖性注射.ServiceCollectionServiceExtensions.反恐精英:
public static IServiceCollection AddScoped<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory) where TService : class;
使用此方法的示例如下:
services.AddScoped<ICustomService>(sp => new CustomService(
sp.GetRequiredService<IAnotherCustomService>(), "Param1", "Param2"));
我理解Func委托和lambda表达式是如何工作的,但我不理解IServiceProvider
在幕后是如何初始化的.