From 8272c9675b0d63b4100aaf57f5067d635b68f5e6 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Mon, 22 Jan 2018 11:39:28 +0100 Subject: [PATCH] Re-adjust quickstart --- docs/guides/getting_started/samples/intro/structure.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/guides/getting_started/samples/intro/structure.cs b/docs/guides/getting_started/samples/intro/structure.cs index be8d9a8be..43e0f33cd 100644 --- a/docs/guides/getting_started/samples/intro/structure.cs +++ b/docs/guides/getting_started/samples/intro/structure.cs @@ -19,9 +19,10 @@ class Program private readonly DiscordSocketClient _client; - // Keep the CommandService around for use with commands. - // This type requires you install the Discord.Net.Commands package. + // Keep the CommandService and DI container around for use with commands. + // These two types require you install the Discord.Net.Commands package. private readonly CommandService _commands; + private readonly IServiceProvider _services; private Program() { @@ -46,12 +47,6 @@ class Program // Again, log level: LogLevel = LogSeverity.Info, - // Setup your DI container. - ServiceProvider = ConfigureServices(), - // If you have a service that's dependant on the CommandService instance, - // use ServiceProviderFactory instead. - //ServiceProviderFactory = (cs => ConfigureServices(cs)), - // There's a few more properties you can set, // for example, case-insensitive commands. CaseSensitiveCommands = false, @@ -61,6 +56,9 @@ class Program _client.Log += Logger; _commands.Log += Logger; + // Setup your DI container. + _services = ConfigureServices(), + } // If any services require the client, or the CommandService, or something else you keep on hand, @@ -131,9 +129,9 @@ class Program // Module classes MUST be marked 'public' or they will be ignored. // You also need to pass your 'IServiceProvider' instance now, // so make sure that's done before you get here. - await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); + await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); // Or add Modules manually if you prefer to be a little more explicit: - await _commands.AddModuleAsync(); + await _commands.AddModuleAsync(_services); // Note that the first one is 'Modules' (plural) and the second is 'Module' (singular). // Subscribe a handler to see if a message invokes a command.