Skip to content

Instantly share code, notes, and snippets.

Created August 3, 2020 08:45
What would you like to do?
public static class CliCommandCollectionExtensions
public static IServiceCollection AddCliCommands(this IServiceCollection services)
Type greetCommandType = typeof(DeployCommand);
Type commandType = typeof(Command);
IEnumerable<Type> commands = greetCommandType
.Where(x => x.Namespace == greetCommandType.Namespace && commandType.IsAssignableFrom(x));
foreach (Type command in commands)
services.AddSingleton(commandType, command);
services.AddSingleton(sp =>
?? throw new ArgumentException("Deployment configuration cannot be missing.");
return services;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment