我正在创建帮助程序类,以简化IServiceCollection库的接口配置和注入.库构造函数包含许多可能先前已注入的依赖项.如果它们尚未插入IServiceCollection,则辅助类应添加它们.如何检测接口是否已注入?
public static void AddClassLibrary(this IServiceCollection services
, IConfiguration configuration)
{
//Constructor for ClassLibrary requires LibraryConfig and IClass2 to be in place
//TODO: check IServiceCollection to see if IClass2 is already in the collection.
//if not, add call helper class to add IClass2 to collection.
//How do I check to see if IClass2 is already in the collection?
services.ConfigurePOCO<LibraryConfig>(configuration.GetSection("ConfigSection"));
services.AddScoped<IClass1, ClassLibrary>();
}
Run Code Online (Sandbox Code Playgroud)