public static ILifetimeSelector AsFirstInheritedInterface(this IServiceTypeSelector obj) { return(obj.As(type => { var firstInterface = type.GetInterfaces()[0]; return new List <Type> { firstInterface }; })); }
public static ILifetimeSelector AsSelfWithAliases(this IServiceTypeSelector selector, IServiceCollection services, ServiceLifetime lifetime, Func <Type, IEnumerable <Type> > aliasSelector) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (aliasSelector == null) { throw new ArgumentNullException(nameof(aliasSelector)); } return(selector.As(type => { var aliases = aliasSelector(type); foreach (var alias in aliases) { services.Add(new ServiceDescriptor(alias, serviceProvider => serviceProvider.GetRequiredService(type), lifetime)); } return new[] { type }; })); }