-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
109 additions
and
201 deletions.
There are no files selected for viewing
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
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
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
13 changes: 13 additions & 0 deletions
13
src/AwsServiceAuthenticator.Commands/CommandConfiguration.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace AwsServiceAuthenticator.Commands; | ||
|
||
public static class CommandConfiguration | ||
{ | ||
public static Dictionary<string, Type> GetCommandMappings() | ||
{ | ||
return new Dictionary<string, Type> | ||
{ | ||
{ "ecr", typeof(EcrAuthCommand) }, | ||
{ "nuget", typeof(NuGetAuthCommand) } | ||
}; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
using AwsServiceAuthenticator.Core.Interfaces; | ||
|
||
namespace AwsServiceAuthenticator.Commands.Logic; | ||
namespace AwsServiceAuthenticator.Commands; | ||
|
||
public class CommandResolver : ICommandResolver | ||
public class CommandResolver(IServiceProvider serviceProvider) : ICommandResolver | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly Dictionary<string, Type> _commands; | ||
|
||
public CommandResolver(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
_commands = new Dictionary<string, Type> | ||
{ | ||
{ "ecr", typeof(EcrAuthCommand) }, | ||
{ "nuget", typeof(NuGetAuthCommand) } | ||
}; | ||
} | ||
private readonly Dictionary<string, Type> _commands = CommandConfiguration.GetCommandMappings(); | ||
|
||
ICommand? ICommandResolver.ResolveCommand(string commandName) | ||
public ICommand? ResolveCommand(string commandName) | ||
{ | ||
if (_commands.TryGetValue(commandName, out var commandType)) | ||
{ | ||
return _serviceProvider.GetService(commandType) as ICommand; | ||
} | ||
return serviceProvider.GetService(commandType) as ICommand; | ||
|
||
throw new ArgumentException("This argument does not exists", nameof(commandName)); | ||
throw new ArgumentException("This argument does not exist", nameof(commandName)); | ||
} | ||
} |
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
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
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
Oops, something went wrong.