FAQ rework, replacing outdated info, better interaction FAQ (#2106)
* FAQ rework, replacing outdated info, better interaction faq * Update docs/faq/basics/getting-started.md Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com> * Update docs/faq/basics/getting-started.md Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com> * Update docs/faq/int_framework/general.md Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com> * fix TOC reference Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com> Co-authored-by: Quin Lynch <lynchquin@gmail.com>
This commit is contained in:
28
docs/faq/basics/samples/DI.cs
Normal file
28
docs/faq/basics/samples/DI.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
public class MyService
|
||||
{
|
||||
public string MyCoolString { get; set; }
|
||||
}
|
||||
public class Setup
|
||||
{
|
||||
public IServiceProvider BuildProvider() =>
|
||||
new ServiceCollection()
|
||||
.AddSingleton<MyService>()
|
||||
.BuildServiceProvider();
|
||||
}
|
||||
public class MyModule : ModuleBase<SocketCommandContext>
|
||||
{
|
||||
// Inject via public settable prop
|
||||
public MyService MyService { get; set; }
|
||||
|
||||
// ...or via the module's constructor
|
||||
|
||||
// private readonly MyService _myService;
|
||||
// public MyModule (MyService myService) => _myService = myService;
|
||||
|
||||
[Command("string")]
|
||||
public Task GetOrSetStringAsync(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_myService.MyCoolString)) _myService.MyCoolString = input;
|
||||
return ReplyAsync(_myService.MyCoolString);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user