diff --git a/src/Dependency/Resolution/Overrides/DependencyOverride.cs b/src/Dependency/Resolution/Overrides/DependencyOverride.cs index c6dc01cb..aced5039 100644 --- a/src/Dependency/Resolution/Overrides/DependencyOverride.cs +++ b/src/Dependency/Resolution/Overrides/DependencyOverride.cs @@ -8,12 +8,11 @@ namespace Unity.Resolution /// given type, regardless of where it appears in the object graph. /// public class DependencyOverride : ResolverOverride, - IEquatable, - IResolve + IEquatable { #region Fields - protected readonly object Value; + protected readonly Type Type; #endregion @@ -27,9 +26,9 @@ public class DependencyOverride : ResolverOverride, /// Type of the dependency. /// Value to override with public DependencyOverride(Type type, object value) - : base(null, type, null) + : base(null, value) { - Value = value; + Type = type; } /// @@ -39,9 +38,8 @@ public DependencyOverride(Type type, object value) /// Name of the dependency /// Value to override with public DependencyOverride(string name, object value) - : base(null, null, name) + : base(name, value) { - Value = value; } @@ -53,23 +51,23 @@ public DependencyOverride(string name, object value) /// Type of the dependency. /// Value to override with public DependencyOverride(Type type, string name, object value) - : base(null, type, name) + : base(name, value) { - Value = value; + Type = type; } /// /// Create an instance of to override /// dependency on cpecific type matching the given type and a name /// - /// Target type + /// Target type to override dependency on /// Name of the dependency /// Type of the dependency. /// Value to override with public DependencyOverride(Type target, Type type, string name, object value) - : base(target, type, name) + : base(target, name, value) { - Value = value; + Type = type; } #endregion @@ -105,26 +103,6 @@ public bool Equals(NamedType other) } #endregion - - - #region IResolverPolicy - - public object Resolve(ref TContext context) - where TContext : IResolveContext - { - if (Value is IResolve policy) - return policy.Resolve(ref context); - - if (Value is IResolverFactory factory) - { - var resolveDelegate = factory.GetResolver(Type); - return resolveDelegate(ref context); - } - - return Value; - } - - #endregion } /// @@ -134,6 +112,24 @@ public object Resolve(ref TContext context) /// Type of the dependency to override. public class DependencyOverride : DependencyOverride { + /// + /// Create an instance of to override + /// dependencies matching the given type and a name + /// + /// + /// This constructor creates an override that will match with any + /// target type as long as the dependency type and name match. To + /// target specific type use + /// method. + /// + /// Target type to override dependency on + /// Name of the dependency + /// Override value + public DependencyOverride(Type target, string name, object value) + : base(target, typeof(T), name, value) + { + } + /// /// Create an instance of to override /// dependencies matching the given type and a name