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.

DI.cs 668 B

123456789101112131415161718192021222324252627
  1. public class MyService
  2. {
  3. public string MyCoolString {get; set;}
  4. }
  5. public class Setup
  6. {
  7. public IServiceProvider BuildProvider() =>
  8. new ServiceCollection()
  9. .AddSingleton<MyService>()
  10. .BuildServiceProvider();
  11. }
  12. public class MyModule : ModuleBase<SocketCommandContext>
  13. {
  14. // Inject via public settable prop
  15. public MyService MyService {get; set;}
  16. // or via ctor
  17. private readonly MyService _myService;
  18. public MyModule (MyService myService) => _myService = myService;
  19. [Command("string")]
  20. public Task GetOrSetStringAsync(string input)
  21. {
  22. if (_myService.MyCoolString == null) _myService.MyCoolString = input;
  23. return ReplyAsync(_myService.MyCoolString);
  24. }
  25. }