in src/JetBrains.Space.AspNetCore/SpaceExtensions.cs [48:78]
public static IServiceCollection AddSpaceClientApi(
this IServiceCollection services,
ServiceLifetime lifetime = ServiceLifetime.Transient)
{
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
// Add prerequisites
services.AddHttpClient();
// Is a Connection registered?
var connectionType = typeof(Connection);
if (!services.Any(it => connectionType.IsAssignableFrom(it.ServiceType)))
{
throw new InvalidOperationException($"The current {nameof(IServiceCollection)} does not yet contain a registration for {nameof(Connection)}. " +
$"To register the Space API client types, call {nameof(AddSpaceConnection)}() before {nameof(AddSpaceClientApi)}(), or manually register a {nameof(Connection)}.");
}
// Add Space ...Client types
var spaceClientType = typeof(ISpaceClient);
var spaceClientAssembly = typeof(TeamDirectoryClient).Assembly;
foreach (var type in spaceClientAssembly.GetTypes()
.Where(it => it.IsClass && !it.IsAbstract && spaceClientType.IsAssignableFrom(it)))
{
services.TryAdd(new ServiceDescriptor(type, type, lifetime));
}
return services;
}