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 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Discord;
  2. using Discord.Commands;
  3. using Discord.WebSocket;
  4. public class ModuleA : ModuleBase
  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
  19. {
  20. // Public settable properties will be injected
  21. public AnnounceService { get; set; }
  22. // Public properties without setters will not
  23. public CommandService Commands { get; }
  24. // Public properties annotated with [DontInject] will not
  25. [DontInject]
  26. public NotificationService { get; set; }
  27. public ModuleB(CommandService commands, IDependencyMap map)
  28. {
  29. Commands = commands;
  30. _notification = map.Get<NotificationService>();
  31. }
  32. }