Я добавляю элемент типа Transient, который принимает несколько элементов TransientItem.
Позже я не хочу перебирать элементы и добавлять их в коллекцию сервисов.
Звучит просто, но я, должно быть, что-то упускаю.
Код: Выделить всё
public interface ITransient : IAppFeatureBase
{
IEnumerable> _items = new Collection> Get() => _items;
}
public struct TransientItem where TEntity : class
{
public readonly IServiceCollection Add(IServiceCollection services) => services.AddTransient();
}
public struct TransientItem where TInterface : class
where TEntity : class, TInterface
{
public readonly IServiceCollection Add(IServiceCollection services) => services.AddTransient();
}
Код: Выделить всё
foreach(Transient trans in features.Where(feat => feat.Type == Features.Transient))
{
foreach(TransientItem item in trans.Get())
{
item.Add(builder.Services);
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... e-the-type