Browse Source

Adjust service collection sample

...according to f89aecb7bf (r141530227)
pull/826/head
Hsu Still 8 years ago
parent
commit
b7909e7c25
1 changed files with 15 additions and 15 deletions
  1. +15
    -15
      docs/guides/commands/samples/dependency_map_setup.cs

+ 15
- 15
docs/guides/commands/samples/dependency_map_setup.cs View File

@@ -1,18 +1,18 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using foxboat.Services;
private IServiceProvider _services;
private CommandService _commands;

public class Commands
public async Task InstallAsync(DiscordSocketClient client)
{
public async Task Install(DiscordSocketClient client)
{
// Here, we will inject the ServiceProvider with
// all of the services our client will use.
_serviceCollection.AddSingleton(client);
_serviceCollection.AddSingleton(new NotificationService());
_serviceCollection.AddSingleton(new DatabaseService());
// ...
await _commands.AddModulesAsync(Assembly.GetEntryAssembly());
}
// Here, we will inject the ServiceProvider with
// all of the services our client will use.
_services = 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.
.AddSingleton<DatabaseService>()
.BuildServiceProvider();
// ...
await _commands.AddModulesAsync(Assembly.GetEntryAssembly());
}

Loading…
Cancel
Save