Merge pull request #520 from james7132/property-injection

Conflicts:
	docs/guides/samples/dependency_module.cs
	src/Discord.Net.Commands/Utilities/ReflectionUtils.cs
This commit is contained in:
Christopher F
2017-02-23 15:51:24 -05:00
4 changed files with 157 additions and 114 deletions

View File

@@ -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,20 @@ public class ModuleA : ModuleBase
public class ModuleB
{
private CommandService _commands;
private NotificationService _notification;
public ModuleB(CommandService commands, NotificationService notifications)
// 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)
{
_commands = commands;
_notification = notifications;
Commands = commands;
}
}
}