-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandExtensions.cs
More file actions
33 lines (27 loc) · 994 Bytes
/
CommandExtensions.cs
File metadata and controls
33 lines (27 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Extensions.DependencyInjection;
using RuangDeveloper.AspNetCore.Command.Commands;
namespace RuangDeveloper.AspNetCore.Command;
/// <summary>
/// Command extensions for the service collection.
/// </summary>
public static class CommandExtensions
{
/// <summary>
/// Adds the commands to the service collection.
/// </summary>
/// <param name="services"></param>
/// <param name="configure"></param>
/// <returns></returns>
public static IServiceCollection AddCommands(this IServiceCollection services, Action<CommandConfiguration> configure)
{
var commandConfiguration = new CommandConfiguration();
configure.Invoke(commandConfiguration);
services.AddSingleton(commandConfiguration);
services.AddTransient<ICommand, ListCommand>();
foreach (var command in commandConfiguration.Commands)
{
services.AddTransient(typeof(ICommand), command);
}
return services;
}
}