Skip to content

Commit

Permalink
Fixed #107
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Apr 24, 2019
1 parent eacad57 commit 65b8287
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/Abstracts/IUnityContainerAsync.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Unity.Injection;
using Unity.Lifetime;
Expand Down Expand Up @@ -97,6 +98,17 @@ public interface IUnityContainerAsync : IDisposable
Task<object> Resolve(Type type, string name, params ResolverOverride[] overrides);


/// <summary>
/// Resolve an instance of the requested type from the container.
/// </summary>
/// <param name="type"><see cref="Type"/> of object to get typeFrom the container.</param>
/// <param name="regex">Pattern to match names to. Only these with successful
/// <see cref="Regex.IsMatch(string name)"/> will be resolved</param>
/// <param name="overrides">Any overrides for the resolve call.</param>
/// <returns>The retrieved object.</returns>
Task<IEnumerable<object>> Resolve(Type type, Regex regex, params ResolverOverride[] overrides);


/// <summary>
/// The parent of this container.
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions src/Abstracts/ResolutionOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

namespace Unity
{
/// <summary>
/// Options indicating how dependency should be resolved
/// </summary>
public enum ResolutionOption
{
/// <summary>
/// Required dependency
/// </summary>
/// <remarks>
/// This dependency should be either resolved or error
/// should be reported.
/// </remarks>
Required,

/// <summary>
/// Optional dependency
/// </summary>
/// <remarks>
/// This dependency should be either resolved or default
/// value will be returned.
/// </remarks>
Optional
}
}
9 changes: 4 additions & 5 deletions src/Dependency/Injection/Members/InjectionField.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Unity.Injection
Expand All @@ -13,10 +12,10 @@ public class InjectionField : MemberInfoBase<FieldInfo>
/// Configure the container to inject the given field name.
/// </summary>
/// <param name="name">Name of property to inject.</param>
/// <param name="optional">Tells Unity if this field is optional.</param>
public InjectionField(string name, bool optional = false)
: base(name, optional ? OptionalDependencyAttribute.Instance
: (object)DependencyAttribute.Instance)
/// <param name="option">Tells Unity if this field is optional.</param>
public InjectionField(string name, ResolutionOption option = ResolutionOption.Required)
: base(name, ResolutionOption.Optional == option ? OptionalDependencyAttribute.Instance
: (object)DependencyAttribute.Instance)
{
}

Expand Down
8 changes: 4 additions & 4 deletions src/Dependency/Injection/Members/InjectionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class InjectionProperty : MemberInfoBase<PropertyInfo>
/// using the value supplied.
/// </summary>
/// <param name="name">Name of property to inject.</param>
/// <param name="optional">Tells Unity if this field is optional.</param>
public InjectionProperty(string name, bool optional = false)
: base(name, optional ? OptionalDependencyAttribute.Instance
: (object)DependencyAttribute.Instance)
/// <param name="option">Tells Unity if this field is optional.</param>
public InjectionProperty(string name, ResolutionOption option = ResolutionOption.Required)
: base(name, ResolutionOption.Optional == option ? OptionalDependencyAttribute.Instance
: (object)DependencyAttribute.Instance)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using Unity.Policy;
using Unity.Resolution;

namespace Unity.Injection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Reflection;
using Unity.Policy;
using Unity.Resolution;

namespace Unity.Injection
Expand Down
1 change: 0 additions & 1 deletion src/Dependency/Injection/Parameters/ResolvedParameter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using Unity.Policy;
using Unity.Resolution;

namespace Unity.Injection
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/Injection/Resolve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static partial class Resolve
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static InjectionMember OptionalField(string name) => new InjectionField(name, true);
public static InjectionMember OptionalField(string name) => new InjectionField(name, ResolutionOption.Optional);

#endregion

Expand All @@ -131,7 +131,7 @@ public static partial class Resolve
#if !NET40
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public static InjectionMember OptionalProperty(string name) => new InjectionProperty(name ?? throw new ArgumentNullException(nameof(name)), true);
public static InjectionMember OptionalProperty(string name) => new InjectionProperty(name ?? throw new ArgumentNullException(nameof(name)), ResolutionOption.Optional);

#endregion
}
Expand Down

0 comments on commit 65b8287

Please sign in to comment.