From ddfd011b8668770121c5f878c933d075109c644e Mon Sep 17 00:00:00 2001 From: Still Hsu <341464@gmail.com> Date: Tue, 5 Jun 2018 11:17:42 +0800 Subject: [PATCH] Fix typos & formatting --- .../commands/samples/command_handler.cs | 8 +-- .../commands/samples/dependency_map_setup.cs | 61 +++++++++---------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/docs/guides/commands/samples/command_handler.cs b/docs/guides/commands/samples/command_handler.cs index 509c2d929..e4531fa41 100644 --- a/docs/guides/commands/samples/command_handler.cs +++ b/docs/guides/commands/samples/command_handler.cs @@ -48,10 +48,10 @@ public class CommandHandler // Keep in mind that result does not indicate a return value // rather an object stating if the command executed successfully. - var result = await _commands.ExecuteAsync( - context: context, - argPost: argPos, - services: null); + var result = await _command.ExecuteAsync( + context: context, + argPos: argPos, + services: null); // Optionally, we may inform the user if the command fails // to be executed; however, this may not always be desired, diff --git a/docs/guides/commands/samples/dependency_map_setup.cs b/docs/guides/commands/samples/dependency_map_setup.cs index 5790ceb4e..118c032ed 100644 --- a/docs/guides/commands/samples/dependency_map_setup.cs +++ b/docs/guides/commands/samples/dependency_map_setup.cs @@ -1,40 +1,34 @@ public class Initialize { - private IServiceProvider _services; - private CommandService _commands; - private DiscordSocketClient _client; + private readonly CommandService _commands; + private readonly DiscordSocketClient _client; - public Initialize(CommandService commands = null, DiscordSocketClient client = null) - { - _commands = commands ?? new CommandService(); - _client = client ?? new DiscordSocketClient(); - } + public Initialize(CommandService commands = null, DiscordSocketClient client = null) + { + _commands = commands ?? new CommandService(); + _client = client ?? new DiscordSocketClient(); + } - public IServiceProvider BuildServiceProvider() - { - // Here, we will inject the ServiceProvider with - // all of the services our client will use. - return new ServiceCollection() - .AddSingleton(_client) - .AddSingleton(_commands) - // You can pass in an instance of the desired type - .AddSingleton(new NotificationService()) - // ...or by using the generic method. - // - // The benefit of using the generic method is that - // ASP.NET DI will attempt to inject the required - // dependencies that are specified under the constructor - // for us. - .AddSingleton() - .AddSingleton() - .BuildServiceProvider(); - } + public IServiceProvider BuildServiceProvider() => new ServiceCollection() + .AddSingleton(_client) + .AddSingleton(_commands) + // You can pass in an instance of the desired type + .AddSingleton(new NotificationService()) + // ...or by using the generic method. + // + // The benefit of using the generic method is that + // ASP.NET DI will attempt to inject the required + // dependencies that are specified under the constructor + // for us. + .AddSingleton() + .AddSingleton() + .BuildServiceProvider(); } public class CommandHandler { + private readonly DiscordSocketClient _client; private readonly CommandService _commands; private readonly IServiceProvider _services; - private readonly DiscordSocketClient _client; public CommandHandler(IServiceProvider services, CommandService commands, DiscordSocketClient client) { @@ -48,8 +42,9 @@ public class CommandHandler // Pass the service provider to the second parameter of // AddModulesAsync to inject dependencies to all modules // that may require them. - await _commands.AddModulesAsync(assembly: Assembly.GetEntryAssembly(), - services: _services); + await _commands.AddModulesAsync( + assembly: Assembly.GetEntryAssembly(), + services: _services); _client.MessageReceived += HandleCommandAsync; } @@ -58,8 +53,10 @@ public class CommandHandler // ... // Pass the service provider to the ExecuteAsync method for // precondition checks. - await _commands.ExecuteAsync(context: context, argPos: argPos, - services: _services); + await _commands.ExecuteAsync( + context: context, + argPos: argPos, + services: _services); // ... } }