This commit is contained in:
Eugene Sadovoi 2017-12-20 16:49:56 -05:00
Родитель bccd21d8d0
Коммит 1b9bed16f3
40 изменённых файлов: 119 добавлений и 103 удалений

Просмотреть файл

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>5.5.0</Version>
<Version>5.4.0</Version>
<PackageReleaseNotes>This package is distributed as .NET Standard 1.0, .NET 4.0, 4.5, 4.7 package.</PackageReleaseNotes>
</PropertyGroup>

Просмотреть файл

@ -18,7 +18,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
private readonly Queue<Expression> _buildPlanExpressions;
private static readonly MethodInfo ResolveDependencyMethod =
typeof(IDependencyResolverPolicy).GetTypeInfo().GetDeclaredMethod(nameof(IDependencyResolverPolicy.Resolve));
typeof(IResolverPolicy).GetTypeInfo().GetDeclaredMethod(nameof(IResolverPolicy.Resolve));
private static readonly MethodInfo GetResolverMethod =
typeof(DynamicBuildPlanGenerationContext).GetTypeInfo()
@ -65,7 +65,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
/// <param name="parameterType"></param>
/// <param name="setOperationExpression"></param>
/// <returns></returns>
public Expression CreateParameterExpression(IDependencyResolverPolicy resolver, Type parameterType, Expression setOperationExpression)
public Expression CreateParameterExpression(IResolverPolicy resolver, Type parameterType, Expression setOperationExpression)
{
// The intent of this is to create a parameter resolving expression block. The following
// pseudo code will hopefully make it clearer as to what we're trying to accomplish (of course actual code
@ -104,7 +104,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
Expression.Constant(null));
}
internal Expression GetResolveDependencyExpression(Type dependencyType, IDependencyResolverPolicy resolver)
internal Expression GetResolveDependencyExpression(Type dependencyType, IResolverPolicy resolver)
{
return Expression.Convert(
Expression.Call(
@ -112,7 +112,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
GetResolverMethod,
ContextParameter,
Expression.Constant(dependencyType, typeof(Type)),
Expression.Constant(resolver, typeof(IDependencyResolverPolicy))),
Expression.Constant(resolver, typeof(IResolverPolicy))),
ResolveDependencyMethod,
ContextParameter),
dependencyType);
@ -166,7 +166,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
/// <param name="dependencyType">Type of the dependency being resolved.</param>
/// <param name="resolver">The configured resolver.</param>
/// <returns>The found dependency resolver.</returns>
public static IDependencyResolverPolicy GetResolver(IBuilderContext context, Type dependencyType, IDependencyResolverPolicy resolver)
public static IResolverPolicy GetResolver(IBuilderContext context, Type dependencyType, IResolverPolicy resolver)
{
var overridden = (context ?? throw new ArgumentNullException(nameof(context))).GetOverriddenResolver(dependencyType);
return overridden ?? resolver;

Просмотреть файл

@ -42,7 +42,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
/// forward direction.
/// </summary>
/// <param name="context">Context of the build operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
var dynamicBuildContext = (DynamicBuildPlanGenerationContext)(context ?? throw new ArgumentNullException(nameof(context))).Existing;
@ -76,6 +76,8 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
{
dynamicBuildContext.AddToBuildPlan(dynamicBuildContext.GetClearCurrentOperationExpression());
}
return null;
}
private IEnumerable<Expression> BuildMethodParameterExpressions(DynamicBuildPlanGenerationContext context, SelectedMethod method, string methodSignature)
@ -83,7 +85,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
int i = 0;
var methodParameters = method.Method.GetParameters();
foreach (IDependencyResolverPolicy parameterResolver in method.GetParameterResolvers())
foreach (IResolverPolicy parameterResolver in method.GetParameterResolvers())
{
yield return context.CreateParameterExpression(
parameterResolver,

Просмотреть файл

@ -53,7 +53,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
/// </summary>
/// <remarks>Existing object is an instance of <see cref="DynamicBuildPlanGenerationContext"/>.</remarks>
/// <param name="context">The context for the operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
DynamicBuildPlanGenerationContext buildContext =
(DynamicBuildPlanGenerationContext)(context ?? throw new ArgumentNullException(nameof(context))).Existing;
@ -69,6 +69,8 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
buildContext.AddToBuildPlan(
Expression.Call(null, SetPerBuildSingletonMethod, buildContext.ContextParameter));
return null;
}
internal Expression CreateInstanceBuildupExpression(DynamicBuildPlanGenerationContext buildContext, IBuilderContext context)
@ -178,7 +180,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
int i = 0;
var constructionParameters = selectedConstructor.Constructor.GetParameters();
foreach (IDependencyResolverPolicy parameterResolver in selectedConstructor.GetParameterResolvers())
foreach (IResolverPolicy parameterResolver in selectedConstructor.GetParameterResolvers())
{
yield return buildContext.CreateParameterExpression(
parameterResolver,

Просмотреть файл

@ -35,7 +35,7 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
/// Called during the chain of responsibility for a build operation.
/// </summary>
/// <param name="context">The context for the operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
var dynamicBuildContext = (DynamicBuildPlanGenerationContext)(context ?? throw new ArgumentNullException(nameof(context))).Existing;
@ -76,6 +76,8 @@ namespace Unity.ObjectBuilder.BuildPlan.DynamicMethod
{
dynamicBuildContext.AddToBuildPlan(dynamicBuildContext.GetClearCurrentOperationExpression());
}
return null;
}
private static MethodInfo GetValidatedPropertySetter(PropertyInfo property)

Просмотреть файл

@ -20,12 +20,12 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
where TInjectionConstructorMarkerAttribute : Attribute
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(ParameterInfo parameter)
protected override IResolverPolicy CreateResolver(ParameterInfo parameter)
{
return new FixedTypeResolverPolicy((parameter ?? throw new ArgumentNullException(nameof(parameter))).ParameterType);
}

Просмотреть файл

@ -49,12 +49,12 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
}
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected abstract IDependencyResolverPolicy CreateResolver(ParameterInfo parameter);
protected abstract IResolverPolicy CreateResolver(ParameterInfo parameter);
private static ConstructorInfo FindInjectionConstructor(Type typeToConstruct)
{

Просмотреть файл

@ -16,7 +16,7 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
public class DefaultUnityConstructorSelectorPolicy : ConstructorSelectorPolicyBase<InjectionConstructorAttribute>
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <remarks>
@ -25,7 +25,7 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
/// for this parameter.</remarks>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(ParameterInfo parameter)
protected override IResolverPolicy CreateResolver(ParameterInfo parameter)
{
// Resolve all DependencyAttributes on this parameter, if any
var attrs = (parameter ?? throw new ArgumentNullException(nameof(parameter))).GetCustomAttributes(false).OfType<DependencyResolutionAttribute>().ToList();

Просмотреть файл

@ -18,12 +18,12 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
where TMarkerAttribute : Attribute
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(ParameterInfo parameter)
protected override IResolverPolicy CreateResolver(ParameterInfo parameter)
{
return new FixedTypeResolverPolicy((parameter ?? throw new ArgumentNullException(nameof(parameter))).ParameterType);
}

Просмотреть файл

@ -53,11 +53,11 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
}
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected abstract IDependencyResolverPolicy CreateResolver(ParameterInfo parameter);
protected abstract IResolverPolicy CreateResolver(ParameterInfo parameter);
}
}

Просмотреть файл

@ -18,12 +18,12 @@ namespace Unity.ObjectBuilder.BuildPlan.Selection
where TResolutionAttribute : Attribute
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> for the given
/// Create a <see cref="IResolverPolicy"/> for the given
/// property.
/// </summary>
/// <param name="property">Property to create resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(PropertyInfo property)
protected override IResolverPolicy CreateResolver(PropertyInfo property)
{
return new FixedTypeResolverPolicy((property ?? throw new ArgumentNullException(nameof(property))).PropertyType);
}

Просмотреть файл

@ -225,12 +225,12 @@ namespace Unity.ObjectBuilder
}
/// <summary>
/// GetOrDefault a <see cref="IDependencyResolverPolicy"/> object for the given <paramref name="dependencyType"/>
/// GetOrDefault a <see cref="IResolverPolicy"/> object for the given <paramref name="dependencyType"/>
/// or null if that dependency hasn't been overridden.
/// </summary>
/// <param name="dependencyType">Type of the dependency.</param>
/// <returns>Resolver to use, or null if no override matches for the current operation.</returns>
public IDependencyResolverPolicy GetOverriddenResolver(Type dependencyType)
public IResolverPolicy GetOverriddenResolver(Type dependencyType)
{
return _resolverOverrides.GetResolver(this, dependencyType);
}

Просмотреть файл

@ -17,12 +17,12 @@ namespace Unity.ObjectBuilder.Policies
public class DefaultUnityMethodSelectorPolicy : MethodSelectorPolicyBase<InjectionMethodAttribute>
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> instance for the given
/// Create a <see cref="IResolverPolicy"/> instance for the given
/// <see cref="ParameterInfo"/>.
/// </summary>
/// <param name="parameter">Parameter to create the resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(ParameterInfo parameter)
protected override IResolverPolicy CreateResolver(ParameterInfo parameter)
{
var attributes = (parameter ?? throw new ArgumentNullException(nameof(parameter))).GetCustomAttributes(false)
.OfType<DependencyResolutionAttribute>()

Просмотреть файл

@ -17,12 +17,12 @@ namespace Unity.ObjectBuilder.Policies
public class DefaultUnityPropertySelectorPolicy : PropertySelectorBase<DependencyResolutionAttribute>
{
/// <summary>
/// Create a <see cref="IDependencyResolverPolicy"/> for the given
/// Create a <see cref="IResolverPolicy"/> for the given
/// property.
/// </summary>
/// <param name="property">Property to create resolver for.</param>
/// <returns>The resolver object.</returns>
protected override IDependencyResolverPolicy CreateResolver(PropertyInfo property)
protected override IResolverPolicy CreateResolver(PropertyInfo property)
{
var attributes =
(property ?? throw new ArgumentNullException(nameof(property))).GetCustomAttributes(typeof(DependencyResolutionAttribute), false)

Просмотреть файл

@ -25,7 +25,7 @@ namespace Unity.ObjectBuilder.Strategies
/// Do the PreBuildUp stage of construction. This is where the actual work is performed.
/// </summary>
/// <param name="context">Current build context.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
Type typeToBuild = context.BuildKey.Type;
if (typeToBuild.IsArray && typeToBuild.GetArrayRank() == 1)
@ -39,6 +39,7 @@ namespace Unity.ObjectBuilder.Strategies
context.Existing = resolver(context);
context.BuildComplete = true;
}
return null;
}
private static object ResolveArray<T>(IBuilderContext context)

Просмотреть файл

@ -16,12 +16,13 @@ namespace Unity.ObjectBuilder.Strategies
/// and if found maps the build key for the current operation.
/// </summary>
/// <param name="context">The context for the operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
var policy = context.Policies.GetPolicy<IBuildKeyMappingPolicy>(context.BuildKey, out _);
if (null == policy) return;
if (null == policy) return null;
context.BuildKey = policy.Map(context.BuildKey, context);
return null;
}
}
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace Unity.ObjectBuilder.Strategies
/// Called during the chain of responsibility for a build operation.
/// </summary>
/// <param name="context">The context for the operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
var plan = context.Policies.Get<IBuildPlanPolicy>(context.OriginalBuildKey, out var buildPlanLocation);
if (plan == null || plan is OverriddenBuildPlanMarkerPolicy)
@ -33,6 +33,7 @@ namespace Unity.ObjectBuilder.Strategies
}
plan?.BuildUp(context);
return null;
}
}
}

Просмотреть файл

@ -27,9 +27,9 @@ namespace Unity.ObjectBuilder.Strategies
/// forward direction.
/// </summary>
/// <param name="context">Context of the build operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
if (context.Existing != null) return;
if (context.Existing != null) return null;
var lifetimePolicy = GetLifetimePolicy(context, out var _);
if (lifetimePolicy is IRequiresRecovery recovery)
@ -43,6 +43,7 @@ namespace Unity.ObjectBuilder.Strategies
context.Existing = existing;
context.BuildComplete = true;
}
return null;
}
/// <summary>
@ -51,7 +52,7 @@ namespace Unity.ObjectBuilder.Strategies
/// phase and executes in reverse order from the PreBuildUp calls.
/// </summary>
/// <param name="context">Context of the build operation.</param>
public override void PostBuildUp(IBuilderContext context)
public override void PostBuildUp(IBuilderContext context, object pre = null)
{
// If we got to this method, then we know the lifetime policy didn't
// find the object. So we go ahead and store it.

Просмотреть файл

@ -48,4 +48,8 @@
<PackageReference Include="Unity.Abstractions" Version="$(UnityAbstractionsVersion)" />
</ItemGroup>
<ItemGroup>
<Folder Include="Builder\Selection\" />
</ItemGroup>
</Project>

Просмотреть файл

@ -98,10 +98,11 @@ namespace Microsoft.Practices.Unity.Tests
{
private int delayMS = 500;
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
Thread.Sleep(this.delayMS);
this.delayMS = this.delayMS == 0 ? 500 : 0;
return null;
}
}
@ -111,13 +112,14 @@ namespace Microsoft.Practices.Unity.Tests
{
private bool shouldThrow = true;
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
if (this.shouldThrow)
{
this.shouldThrow = false;
throw new Exception("Throwing from buildup chain");
}
return null;
}
}
}

Просмотреть файл

@ -4,9 +4,11 @@
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Tests.TestDoubles;
using Microsoft.Practices.Unity.TestSupport;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity.Builder;
using Unity.Tests.TestDoubles;
using IMockConfiguration = Microsoft.Practices.Unity.TestSupport.IMockConfiguration;
using MockContainerExtension = Microsoft.Practices.Unity.TestSupport.MockContainerExtension;
namespace Unity.Tests.Extension
{

Просмотреть файл

@ -47,7 +47,7 @@ namespace Microsoft.Practices.Unity.Tests
Type expectedType = typeof(ILogger);
ResolvedParameter parameter = new ResolvedParameter<ILogger>();
IDependencyResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
AssertExtensions.IsInstanceOfType(resolver, typeof(NamedTypeDependencyResolverPolicy));
Assert.AreEqual(expectedType, ((NamedTypeDependencyResolverPolicy)resolver).Type);
@ -61,7 +61,7 @@ namespace Microsoft.Practices.Unity.Tests
string name = "special";
ResolvedParameter parameter = new ResolvedParameter(expectedType, name);
IDependencyResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
AssertExtensions.IsInstanceOfType(resolver, typeof(NamedTypeDependencyResolverPolicy));
Assert.AreEqual(expectedType, ((NamedTypeDependencyResolverPolicy)resolver).Type);
@ -84,7 +84,7 @@ namespace Microsoft.Practices.Unity.Tests
InjectionParameter parameter = (InjectionParameter)values[0];
Assert.AreEqual(typeof(int), parameter.ParameterType);
IDependencyResolverPolicy policy = parameter.GetResolverPolicy(null);
IResolverPolicy policy = parameter.GetResolverPolicy(null);
int result = (int)policy.Resolve(null);
Assert.AreEqual(15, result);
@ -132,7 +132,7 @@ namespace Microsoft.Practices.Unity.Tests
private void AssertExpectedValue(InjectionParameter parameter, Type expectedType, object expectedValue)
{
IDependencyResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType);
object result = resolver.Resolve(null);
Assert.AreEqual(expectedType, parameter.ParameterType);

Просмотреть файл

@ -98,9 +98,10 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
{
public INamedType BuildKey;
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
this.BuildKey = context.BuildKey;
return null;
}
}
}

Просмотреть файл

@ -73,7 +73,7 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
return new MockStrategyChain(new[] { this });
}
public void PreBuildUp(IBuilderContext context)
public object PreBuildUp(IBuilderContext context)
{
this.childContext = this.parentContext.ChildContext;
this.receivedContext = context;
@ -82,9 +82,11 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
{
throw new Exception();
}
return null;
}
public void PostBuildUp(IBuilderContext context)
public void PostBuildUp(IBuilderContext context, object pre = null)
{
}
}

Просмотреть файл

@ -232,9 +232,9 @@ namespace Unity.Tests.ObjectBuilder
public class TestSingleArgumentMethodSelectorPolicy<T> : IMethodSelectorPolicy
{
private IDependencyResolverPolicy resolverPolicy;
private IResolverPolicy resolverPolicy;
public TestSingleArgumentMethodSelectorPolicy(IDependencyResolverPolicy resolverPolicy)
public TestSingleArgumentMethodSelectorPolicy(IResolverPolicy resolverPolicy)
{
this.resolverPolicy = resolverPolicy;
}

Просмотреть файл

@ -113,9 +113,9 @@ namespace Unity.Tests.ObjectBuilder
public class TestSingleArgumentConstructorSelectorPolicy<T> : IConstructorSelectorPolicy
{
private IDependencyResolverPolicy parameterResolverPolicy;
private IResolverPolicy parameterResolverPolicy;
public TestSingleArgumentConstructorSelectorPolicy(IDependencyResolverPolicy parameterResolverPolicy)
public TestSingleArgumentConstructorSelectorPolicy(IResolverPolicy parameterResolverPolicy)
{
this.parameterResolverPolicy = parameterResolverPolicy;
}

Просмотреть файл

@ -11,11 +11,11 @@ using Unity.Builder;
using Unity.Builder.Operation;
using Unity.Builder.Selection;
using Unity.Container;
using Unity.Lifetime;
using Unity.ObjectBuilder.BuildPlan.DynamicMethod;
using Unity.ObjectBuilder.BuildPlan.Selection;
using Unity.ObjectBuilder.Strategies;
using Unity.Policy;
using Unity.Policy.Selection;
using DependencyAttribute = Microsoft.Practices.ObjectBuilder2.Tests.TestDoubles.DependencyAttribute;
using InjectionConstructorAttribute = Microsoft.Practices.ObjectBuilder2.Tests.TestDoubles.InjectionConstructorAttribute;
@ -146,14 +146,14 @@ namespace Unity.Tests.ObjectBuilder
public class TestSinglePropertySelectorPolicy<T> : IPropertySelectorPolicy
{
private IDependencyResolverPolicy resolverPolicy;
private IResolverPolicy resolverPolicy;
public TestSinglePropertySelectorPolicy(IDependencyResolverPolicy resolverPolicy)
public TestSinglePropertySelectorPolicy(IResolverPolicy resolverPolicy)
{
this.resolverPolicy = resolverPolicy;
}
public IEnumerable<SelectedProperty> SelectProperties(IBuilderContext context, IPolicyList resolverPolicyDestination)
public IEnumerable<ISelectedProperty> SelectProperties(IBuilderContext context, IPolicyList resolverPolicyDestination)
{
const BindingFlags Filter = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
var firstProperty = typeof(T).GetProperties(Filter).First();

Просмотреть файл

@ -7,11 +7,10 @@ using System.Reflection;
using Microsoft.Practices.ObjectBuilder2.Tests.TestDoubles;
using Microsoft.Practices.Unity.TestSupport;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity;
using Unity.Builder;
using Unity.Builder.Selection;
using Unity.ObjectBuilder.BuildPlan.Selection;
using Unity.Policy;
using Unity.Policy.Selection;
namespace Microsoft.Practices.ObjectBuilder2.Tests
{
@ -48,7 +47,7 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
{
IPropertySelectorPolicy selector = new PropertySelectorPolicy<DependencyAttribute>();
IBuilderContext context = GetContext(t);
var properties = new List<SelectedProperty>(selector.SelectProperties(context, context.PersistentPolicies));
var properties = new List<ISelectedProperty>(selector.SelectProperties(context, context.PersistentPolicies));
return properties.Select(sp => sp.Property).ToList();
}

Просмотреть файл

@ -54,7 +54,7 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
private class ThrowingStrategy : BuilderStrategy
{
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
throw new Exception("Throwing from strategy");
}

Просмотреть файл

@ -83,7 +83,7 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
private int sleepTimeMS = 500;
private static object @lock = new object();
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
// Sleep
lock (SleepingStrategy.@lock)
@ -92,15 +92,17 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
}
this.sleepTimeMS = this.sleepTimeMS == 0 ? 500 : 0;
return null;
}
}
// A test strategy that just creates an object.
internal class NewObjectStrategy : BuilderStrategy
{
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
context.Existing = new object();
return null;
}
}
}

Просмотреть файл

@ -83,12 +83,12 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests
private class FakeStrategy : IBuilderStrategy
{
public void PreBuildUp(IBuilderContext context)
public object PreBuildUp(IBuilderContext context)
{
throw new NotImplementedException();
}
public void PostBuildUp(IBuilderContext context)
public void PostBuildUp(IBuilderContext context, object pre = null)
{
throw new NotImplementedException();
}

Просмотреть файл

@ -17,12 +17,14 @@ namespace Microsoft.Practices.ObjectBuilder2.Tests.Utility
/// forward direction.
/// </summary>
/// <param name="context">Context of the build operation.</param>
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
if (context.Existing == null)
{
context.Existing = Activator.CreateInstance(context.BuildKey.Type);
}
return null;
}
}
}

Просмотреть файл

@ -204,7 +204,7 @@ namespace Microsoft.Practices.Unity.Tests
throw new NotImplementedException();
}
public IDependencyResolverPolicy GetOverriddenResolver(Type dependencyType)
public IResolverPolicy GetOverriddenResolver(Type dependencyType)
{
throw new NotImplementedException();
}

Просмотреть файл

@ -188,9 +188,9 @@ namespace Microsoft.Practices.Unity.Tests
private class InjectedObjectConfigurationExtension : UnityContainerExtension
{
private readonly IDependencyResolverPolicy resolverPolicy;
private readonly IResolverPolicy resolverPolicy;
public InjectedObjectConfigurationExtension(IDependencyResolverPolicy resolverPolicy)
public InjectedObjectConfigurationExtension(IResolverPolicy resolverPolicy)
{
this.resolverPolicy = resolverPolicy;
}
@ -204,9 +204,9 @@ namespace Microsoft.Practices.Unity.Tests
private class InjectedObjectSelectorPolicy : IConstructorSelectorPolicy
{
private readonly IDependencyResolverPolicy resolverPolicy;
private readonly IResolverPolicy resolverPolicy;
public InjectedObjectSelectorPolicy(IDependencyResolverPolicy resolverPolicy)
public InjectedObjectSelectorPolicy(IResolverPolicy resolverPolicy)
{
this.resolverPolicy = resolverPolicy;
}
@ -245,13 +245,15 @@ namespace Microsoft.Practices.Unity.Tests
this.container = container;
}
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
if ((NamedTypeBuildKey)context.BuildKey == NamedTypeBuildKey.Make<IUnityContainer>())
{
context.Existing = this.container;
context.BuildComplete = true;
}
return null;
}
}
}

Просмотреть файл

@ -90,7 +90,7 @@ namespace Microsoft.Practices.Unity.Tests
Assert.AreSame(expectedCtor, result.Constructor);
}
private static void AssertPolicyIsCorrect(IDependencyResolverPolicy policy)
private static void AssertPolicyIsCorrect(IResolverPolicy policy)
{
Assert.IsNotNull(policy);
AssertExtensions.IsInstanceOfType(policy, typeof(LiteralValueDependencyResolverPolicy));
@ -195,7 +195,7 @@ namespace Microsoft.Practices.Unity.Tests
throw new NotImplementedException();
}
public IDependencyResolverPolicy GetOverriddenResolver(Type dependencyType)
public IResolverPolicy GetOverriddenResolver(Type dependencyType)
{
throw new NotImplementedException();
}

Просмотреть файл

@ -6,7 +6,7 @@ using Unity.Policy;
namespace Microsoft.Practices.ObjectBuilder2.Tests.TestDoubles
{
public class CurrentOperationSensingResolverPolicy<T> : IDependencyResolverPolicy
public class CurrentOperationSensingResolverPolicy<T> : IResolverPolicy
{
public object CurrentOperation;

Просмотреть файл

@ -7,7 +7,7 @@ using Unity.Policy;
namespace Microsoft.Practices.ObjectBuilder2.Tests.TestDoubles
{
public class ExceptionThrowingTestResolverPolicy : IDependencyResolverPolicy
public class ExceptionThrowingTestResolverPolicy : IResolverPolicy
{
private Exception exceptionToThrow;

Просмотреть файл

@ -1,12 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using Microsoft.Practices.ObjectBuilder2;
using Unity;
using Microsoft.Practices.Unity.Tests.TestDoubles;
using Unity.Builder;
using Unity.Builder.Strategy;
using Unity.Policy;
namespace Microsoft.Practices.Unity.Tests.TestDoubles
namespace Unity.Tests.TestDoubles
{
/// <summary>
/// A small noop strategy that lets us check afterwards to
@ -14,40 +13,29 @@ namespace Microsoft.Practices.Unity.Tests.TestDoubles
/// </summary>
internal class SpyStrategy : BuilderStrategy
{
private IBuilderContext context = null;
private object buildKey = null;
private object existing = null;
private bool buildUpWasCalled = false;
private IBuilderContext context;
private object buildKey;
private object existing;
private bool buildUpWasCalled;
public override void PreBuildUp(IBuilderContext context)
public override object PreBuildUp(IBuilderContext context)
{
this.buildUpWasCalled = true;
buildUpWasCalled = true;
this.context = context;
this.buildKey = context.BuildKey;
this.existing = context.Existing;
buildKey = context.BuildKey;
existing = context.Existing;
this.UpdateSpyPolicy(context);
UpdateSpyPolicy(context);
return null;
}
public IBuilderContext Context
{
get { return this.context; }
}
public IBuilderContext Context => context;
public object BuildKey
{
get { return this.buildKey; }
}
public object BuildKey => buildKey;
public object Existing
{
get { return this.existing; }
}
public object Existing => existing;
public bool BuildUpWasCalled
{
get { return this.buildUpWasCalled; }
}
public bool BuildUpWasCalled => buildUpWasCalled;
private void UpdateSpyPolicy(IBuilderContext context)
{

Просмотреть файл

@ -101,7 +101,7 @@ namespace Microsoft.Practices.Unity.TestSupport
resolverOverrides.AddRange(newOverrides);
}
public IDependencyResolverPolicy GetOverriddenResolver(Type dependencyType)
public IResolverPolicy GetOverriddenResolver(Type dependencyType)
{
return resolverOverrides.GetResolver(this, dependencyType);
}

Просмотреть файл

@ -1,11 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using Microsoft.Practices.Unity.Tests.TestDoubles;
using Microsoft.Practices.Unity.TestSupport;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Unity;
using Unity.Builder;
using Unity.Extension;
using Unity.Tests.TestDoubles;
using IMockConfiguration = Microsoft.Practices.Unity.TestSupport.IMockConfiguration;
using MockContainerExtension = Microsoft.Practices.Unity.TestSupport.MockContainerExtension;
namespace Microsoft.Practices.Unity.Tests
{