Created
August 3, 2020 08:45
-
-
Save carmeleve/1598377a3c4c89ea4a1b6ada4bf79026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CliCommandCollectionExtensions | |
{ | |
public static IServiceCollection AddCliCommands(this IServiceCollection services) | |
{ | |
Type greetCommandType = typeof(DeployCommand); | |
Type commandType = typeof(Command); | |
IEnumerable<Type> commands = greetCommandType | |
.Assembly | |
.GetExportedTypes() | |
.Where(x => x.Namespace == greetCommandType.Namespace && commandType.IsAssignableFrom(x)); | |
foreach (Type command in commands) | |
{ | |
services.AddSingleton(commandType, command); | |
} | |
services.AddSingleton(sp => | |
{ | |
return | |
sp.GetRequiredService<IConfiguration>().GetSection("Deployment").Get<DeploymentOptions>() | |
?? 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