Browse Source

Remove Auto-Injection

this should be handled by #520
tags/1.0-rc
Christopher F 8 years ago
parent
commit
40ede62e4d
2 changed files with 0 additions and 30 deletions
  1. +0
    -15
      src/Discord.Net.Commands/Attributes/InjectAttribute.cs
  2. +0
    -15
      src/Discord.Net.Commands/Utilities/ReflectionUtils.cs

+ 0
- 15
src/Discord.Net.Commands/Attributes/InjectAttribute.cs View File

@@ -1,15 +0,0 @@
using System;

namespace Discord.Commands
{
/// <summary>
/// Indicates that this property should be filled in by dependency injection.
/// </summary>
/// <remarks>
/// This property **MUST** have a setter.
/// </remarks>
[AttributeUsage(AttributeTargets.Property)]
public sealed class InjectAttribute : Attribute
{
}
}

+ 0
- 15
src/Discord.Net.Commands/Utilities/ReflectionUtils.cs View File

@@ -43,21 +43,6 @@ namespace Discord.Commands
try
{
T instance = (T)constructor.Invoke(args);
var fields = instance.GetType().GetRuntimeProperties().Where(p => p.GetCustomAttribute<InjectAttribute>() != null).Where(p => p.CanWrite);
foreach (var field in fields)
{
object arg;
if (map == null || !map.TryGet(field.PropertyType, out arg))
{
if (field.PropertyType == typeof(CommandService))
arg = service;
else if (field.PropertyType == typeof(IDependencyMap))
arg = map;
else
throw new InvalidOperationException($"Failed to inject \"{typeInfo.FullName}\", dependency \"{field.PropertyType.FullName}\" was not found.");
}
field.SetValue(instance, arg);
}
return instance;
}
catch (Exception ex)


Loading…
Cancel
Save