Update docs to reflect the change.
This commit is contained in:
@@ -166,6 +166,11 @@ that are placed in the constructor must be injected into an
|
||||
@Discord.Commands.IDependencyMap. Alternatively, you may accept an
|
||||
IDependencyMap as an argument and extract services yourself.
|
||||
|
||||
### Module Properties
|
||||
|
||||
Modules with public settable properties will be have them injected after
|
||||
construction.
|
||||
|
||||
### Module Groups
|
||||
|
||||
Module Groups allow you to create a module where commands are prefixed.
|
||||
@@ -212,10 +217,16 @@ Your modules will automatically be loaded with this dependency map.
|
||||
In the constructor of your module, any parameters will be filled in by
|
||||
the @Discord.Commands.IDependencyMap you pass into `LoadAssembly`.
|
||||
|
||||
Any publicly settable properties will also be filled in the same manner.
|
||||
|
||||
>[!NOTE]
|
||||
> Annotating a property with the [DontInject] attribute will prevent it from
|
||||
being injected.
|
||||
|
||||
>[!NOTE]
|
||||
>If you accept `CommandService` or `IDependencyMap` as a parameter in
|
||||
your constructor, these parameters will be filled by the
|
||||
CommandService the module was loaded from, and the DependencyMap passed
|
||||
your constructor or as an injectable property, these entries will be filled
|
||||
by the CommandService the module was loaded from, and the DependencyMap passed
|
||||
into it, respectively.
|
||||
|
||||
[!code-csharp[DependencyMap in Modules](samples/dependency_module.cs)]
|
||||
|
||||
@@ -6,6 +6,7 @@ public class ModuleA : ModuleBase
|
||||
{
|
||||
private readonly DatabaseService _database;
|
||||
|
||||
// Dependencies can be injected via the constructor
|
||||
public ModuleA(DatabaseService database)
|
||||
{
|
||||
_database = database;
|
||||
@@ -20,12 +21,21 @@ public class ModuleA : ModuleBase
|
||||
|
||||
public class ModuleB
|
||||
{
|
||||
private CommandService _commands;
|
||||
private NotificationService _notification;
|
||||
|
||||
// Public settable properties will be injected
|
||||
public AnnounceService { get; set; }
|
||||
|
||||
// Public properties without setters will not
|
||||
public CommandService Commands { get; }
|
||||
|
||||
// Public properties annotated with [DontInject] will not
|
||||
[DontInject]
|
||||
public NotificationService { get; set; }
|
||||
|
||||
public ModuleB(CommandService commands, IDependencyMap map)
|
||||
{
|
||||
_commands = commands;
|
||||
Commands = commands;
|
||||
_notification = map.Get<NotificationService>();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user