From f19730e43385c2e07b19b9677a67d061b51661be Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 3 Mar 2018 20:36:06 -0500 Subject: [PATCH] AddModuleAsync/AddModulesAsync should not require an IServiceProvider If one is not passed, they will default to an EmptyServiceProvider This resolves issues where since the merging of OnModuleBuilding, users were effectively forced to use the DI pattern, where before they were not. While this isn't necessarily a bad idea, we shouldn't just change this behavior for no reason (though I assume making the IServiceProvider argument required was a mistake) --- src/Discord.Net.Commands/CommandService.cs | 10 +++++++--- src/Discord.Net.Commands/Utilities/ReflectionUtils.cs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 7efc1bc62..d79a3a03b 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -95,9 +95,11 @@ namespace Discord.Commands _moduleLock.Release(); } } - public Task AddModuleAsync(IServiceProvider services) => AddModuleAsync(typeof(T), services); - public async Task AddModuleAsync(Type type, IServiceProvider services) + public Task AddModuleAsync(IServiceProvider services = null) => AddModuleAsync(typeof(T), services); + public async Task AddModuleAsync(Type type, IServiceProvider services = null) { + services = services ?? EmptyServiceProvider.Instance; + await _moduleLock.WaitAsync().ConfigureAwait(false); try { @@ -120,8 +122,10 @@ namespace Discord.Commands _moduleLock.Release(); } } - public async Task> AddModulesAsync(Assembly assembly, IServiceProvider services) + public async Task> AddModulesAsync(Assembly assembly, IServiceProvider services = null) { + services = services ?? EmptyServiceProvider.Instance; + await _moduleLock.WaitAsync().ConfigureAwait(false); try { diff --git a/src/Discord.Net.Commands/Utilities/ReflectionUtils.cs b/src/Discord.Net.Commands/Utilities/ReflectionUtils.cs index ab88f66ae..30dd7c36b 100644 --- a/src/Discord.Net.Commands/Utilities/ReflectionUtils.cs +++ b/src/Discord.Net.Commands/Utilities/ReflectionUtils.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection;