You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dependency_module.cs 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Discord;
  2. using Discord.Commands;
  3. using Discord.WebSocket;
  4. public class ModuleA : ModuleBase<SocketCommandContext>
  5. {
  6. private readonly DatabaseService _database;
  7. // Dependencies can be injected via the constructor
  8. public ModuleA(DatabaseService database)
  9. {
  10. _database = database;
  11. }
  12. public async Task ReadFromDb()
  13. {
  14. var x = _database.getX();
  15. await ReplyAsync(x);
  16. }
  17. }
  18. public class ModuleB : ModuleBase<SocketCommandContext>
  19. {
  20. // Public settable properties will be injected.
  21. public AnnounceService Announce { get; set; }
  22. // Public properties without setters will not be injected.
  23. public CommandService Commands { get; }
  24. // Public properties annotated with [DontInject] will not
  25. // be injected.
  26. [DontInject]
  27. public NotificationService NotificationService { get; set; }
  28. public ModuleB(CommandService commands)
  29. {
  30. Commands = commands;
  31. }
  32. }