From b70ae4128599b6c7f3fa9890d6765e5c8fd505e5 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sun, 18 Mar 2018 15:29:23 -0400 Subject: [PATCH] AddModule(s)Async should be explicit about IServiceProvider In f19730e4, AddModule(s)Async was changed so that the IServiceProvider was optional, both at compile time and runtime. This had the side effect of meaning that there was no longer a compile-time hint that users would need to pass an IServiceProvider to AddModulesAsync. I assumed this would not be an issue - users would recognize the runtime exception here and self correct - but activity in our Discord support channel would indicate otherwise. We now require the user to explicitly opt-out of dependency injection - they are still free to pass null in place of an IServiceProvider if they do not intend to use one, and the library will handle this at runtime. --- src/Discord.Net.Commands/CommandService.cs | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index de990ab47..f4fbcf8b2 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -95,8 +95,15 @@ namespace Discord.Commands _moduleLock.Release(); } } - public Task AddModuleAsync(IServiceProvider services = null) => AddModuleAsync(typeof(T), services); - public async Task AddModuleAsync(Type type, IServiceProvider services = null) + + /// + /// Add a command module from a type + /// + /// The type of module + /// An IServiceProvider for your dependency injection solution, if using one - otherwise, pass null + /// A built module + public Task AddModuleAsync(IServiceProvider services) => AddModuleAsync(typeof(T), services); + public async Task AddModuleAsync(Type type, IServiceProvider services) { services = services ?? EmptyServiceProvider.Instance; @@ -122,7 +129,13 @@ namespace Discord.Commands _moduleLock.Release(); } } - public async Task> AddModulesAsync(Assembly assembly, IServiceProvider services = null) + /// + /// Add command modules from an assembly + /// + /// The assembly containing command modules + /// An IServiceProvider for your dependency injection solution, if using one - otherwise, pass null + /// A collection of built modules + public async Task> AddModulesAsync(Assembly assembly, IServiceProvider services) { services = services ?? EmptyServiceProvider.Instance; @@ -278,9 +291,9 @@ namespace Discord.Commands return SearchResult.FromError(CommandError.UnknownCommand, "Unknown command."); } - public Task ExecuteAsync(ICommandContext context, int argPos, IServiceProvider services = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + public Task ExecuteAsync(ICommandContext context, int argPos, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) => ExecuteAsync(context, context.Message.Content.Substring(argPos), services, multiMatchHandling); - public async Task ExecuteAsync(ICommandContext context, string input, IServiceProvider services = null, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) + public async Task ExecuteAsync(ICommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception) { services = services ?? EmptyServiceProvider.Instance;