Skip to content

Commit

Permalink
Deprecated Microsoft.Practices.Unity.InterceptionExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Oct 17, 2017
1 parent 95fbc3f commit 7a99a90
Show file tree
Hide file tree
Showing 170 changed files with 1,214 additions and 1,422 deletions.
19 changes: 7 additions & 12 deletions src/ContainerIntegration/AdditionalInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

using System;
using System.Globalization;
using Microsoft.Practices.ObjectBuilder2;
using Unity.Interception.ContainerIntegration.ObjectBuilder;
using Unity.Interception.Properties;
using Microsoft.Practices.Unity.Utility;
using Unity;
using Unity.Policy;

namespace Microsoft.Practices.Unity.InterceptionExtension
namespace Unity.Interception.ContainerIntegration
{
/// <summary>
/// Stores information about a single <see cref="Type"/> to be an additional interface for an intercepted object and
/// configures a container accordingly.
/// </summary>
public class AdditionalInterface : InterceptionMember
{
private readonly Type additionalInterface;
private readonly Type _additionalInterface;

/// <summary>
/// Initializes a new instance of the <see cref="AdditionalInterface"/> with a
Expand All @@ -27,22 +25,19 @@ public class AdditionalInterface : InterceptionMember
/// <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">when <paramref name="additionalInterface"/> is not an interface.
/// </exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods",
Justification = "Validation done by Guard class")]
public AdditionalInterface(Type additionalInterface)
{
Guard.ArgumentNotNull(additionalInterface, "additionalInterface");
if (!additionalInterface.IsInterface)
if (!(additionalInterface ?? throw new ArgumentNullException(nameof(additionalInterface))).IsInterface)
{
throw new ArgumentException(
string.Format(
CultureInfo.CurrentCulture,
Resources.ExceptionTypeIsNotInterface,
additionalInterface.Name),
"additionalInterface");
nameof(additionalInterface));
}

this.additionalInterface = additionalInterface;
_additionalInterface = additionalInterface;
}

/// <summary>
Expand All @@ -57,7 +52,7 @@ public override void AddPolicies(Type serviceType, Type implementationType, stri
{
AdditionalInterfacesPolicy policy =
AdditionalInterfacesPolicy.GetOrCreate(policies, implementationType, name);
policy.AddAdditionalInterface(this.additionalInterface);
policy.AddAdditionalInterface(_additionalInterface);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ContainerIntegration/DefaultInterceptionBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System;
using Microsoft.Practices.ObjectBuilder2;
using Unity;
using Unity.Interception.ContainerIntegration.ObjectBuilder;
using Unity.Interception.InterceptionBehaviors;
using Unity.Policy;

namespace Microsoft.Practices.Unity.InterceptionExtension
namespace Unity.Interception.ContainerIntegration
{
/// <summary>
/// An injection member that lets you specify behaviors that should
Expand Down
48 changes: 24 additions & 24 deletions src/ContainerIntegration/DefaultInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity.Utility;
using Unity;
using Unity.Builder;
using Unity.Interception.ContainerIntegration.ObjectBuilder;
using Unity.Interception.Interceptors;
using Unity.Interception.Interceptors.InstanceInterceptors;
using Unity.Interception.Interceptors.TypeInterceptors;
using Unity.Interception.Utilities;
using Unity.Policy;
using Unity.Registration;

namespace Microsoft.Practices.Unity.InterceptionExtension
namespace Unity.Interception.ContainerIntegration
{
/// <summary>
/// A <see cref="InjectionMember"/> that can be passed to the
Expand All @@ -19,8 +21,8 @@ namespace Microsoft.Practices.Unity.InterceptionExtension
/// </summary>
public class DefaultInterceptor : InjectionMember
{
private readonly IInterceptor interceptor;
private readonly NamedTypeBuildKey interceptorKey;
private readonly IInterceptor _interceptor;
private readonly NamedTypeBuildKey _interceptorKey;

/// <summary>
/// Construct a new <see cref="DefaultInterceptor"/> instance that,
Expand All @@ -30,9 +32,7 @@ public class DefaultInterceptor : InjectionMember
/// <param name="interceptor">Interceptor to use.</param>
public DefaultInterceptor(IInterceptor interceptor)
{
Guard.ArgumentNotNull(interceptor, "intereptor");

this.interceptor = interceptor;
_interceptor = interceptor ?? throw new ArgumentNullException(nameof(interceptor));
}

/// <summary>
Expand All @@ -47,7 +47,7 @@ public DefaultInterceptor(Type interceptorType, string name)
Guard.ArgumentNotNull(interceptorType, "interceptorType");
Guard.TypeIsAssignable(typeof(IInterceptor), interceptorType, "interceptorType");

this.interceptorKey = new NamedTypeBuildKey(interceptorType, name);
_interceptorKey = new NamedTypeBuildKey(interceptorType, name);
}

/// <summary>
Expand All @@ -72,58 +72,58 @@ public DefaultInterceptor(Type interceptorType)
/// <param name="policies">Policy list to add policies to.</param>
public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
{
if (this.IsInstanceInterceptor)
if (IsInstanceInterceptor)
{
this.AddDefaultInstanceInterceptor(implementationType, policies);
AddDefaultInstanceInterceptor(implementationType, policies);
}
else
{
this.AddDefaultTypeInterceptor(implementationType, policies);
AddDefaultTypeInterceptor(implementationType, policies);
}
}

private bool IsInstanceInterceptor
{
get
{
if (this.interceptor != null)
if (_interceptor != null)
{
return this.interceptor is IInstanceInterceptor;
return _interceptor is IInstanceInterceptor;
}
return typeof(IInstanceInterceptor).IsAssignableFrom(this.interceptorKey.Type);
return typeof(IInstanceInterceptor).IsAssignableFrom(_interceptorKey.Type);
}
}

private void AddDefaultInstanceInterceptor(Type typeToIntercept, IPolicyList policies)
{
IInstanceInterceptionPolicy policy;

if (this.interceptor != null)
if (_interceptor != null)
{
policy = new FixedInstanceInterceptionPolicy((IInstanceInterceptor)this.interceptor);
policy = new FixedInstanceInterceptionPolicy((IInstanceInterceptor)_interceptor);
}
else
{
policy = new ResolvedInstanceInterceptionPolicy(this.interceptorKey);
policy = new ResolvedInstanceInterceptionPolicy(_interceptorKey);
}

policies.Set<IInstanceInterceptionPolicy>(policy, typeToIntercept);
policies.Set(policy, typeToIntercept);
}

private void AddDefaultTypeInterceptor(Type typeToIntercept, IPolicyList policies)
{
ITypeInterceptionPolicy policy;

if (this.interceptor != null)
if (_interceptor != null)
{
policy = new FixedTypeInterceptionPolicy((ITypeInterceptor)this.interceptor);
policy = new FixedTypeInterceptionPolicy((ITypeInterceptor)_interceptor);
}
else
{
policy = new ResolvedTypeInterceptionPolicy(this.interceptorKey);
policy = new ResolvedTypeInterceptionPolicy(_interceptorKey);
}

policies.Set<ITypeInterceptionPolicy>(policy, typeToIntercept);
policies.Set(policy, typeToIntercept);
}
}

Expand Down
44 changes: 20 additions & 24 deletions src/ContainerIntegration/Interception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

using System;
using System.Globalization;
using Microsoft.Practices.ObjectBuilder2;
using Unity.Interception.Properties;
using Unity;
using Unity.Builder;
using Unity.Extension;
using Unity.Interception.ContainerIntegration.ObjectBuilder;
using Unity.Interception.Interceptors;
using Unity.Interception.Interceptors.InstanceInterceptors;
using Unity.Interception.Interceptors.TypeInterceptors;
using Unity.Interception.PolicyInjection;
using Unity.Interception.PolicyInjection.Policies;
using Unity.Interception.Properties;
using Unity.Interception.Utilities;
using Unity.Policy;
using Guard = Microsoft.Practices.Unity.Utility.Guard;
using Unity.Strategy;

namespace Microsoft.Practices.Unity.InterceptionExtension
namespace Unity.Interception.ContainerIntegration
{
/// <summary>
/// A Unity container extension that allows you to configure
Expand All @@ -36,10 +40,8 @@ protected override void Initialize()
// have taken place.
Context.Strategies.AddNew<InstanceInterceptionStrategy>(UnityBuildStage.Setup);
Context.Strategies.AddNew<TypeInterceptionStrategy>(UnityBuildStage.PreCreation);
Context.Container
.RegisterInstance<InjectionPolicy>(
typeof(AttributeDrivenPolicy).AssemblyQualifiedName,
new AttributeDrivenPolicy());
Context.Container.RegisterInstance<InjectionPolicy>(typeof(AttributeDrivenPolicy).AssemblyQualifiedName,
new AttributeDrivenPolicy());
}

/// <summary>
Expand Down Expand Up @@ -76,7 +78,7 @@ public Interception SetInterceptorFor(Type typeToIntercept, string name, ITypeIn
/// <returns>This extension object.</returns>
public Interception SetInterceptorFor(Type typeToIntercept, ITypeInterceptor interceptor)
{
return this.SetInterceptorFor(typeToIntercept, null, interceptor);
return SetInterceptorFor(typeToIntercept, null, interceptor);
}

/// <summary>
Expand All @@ -86,10 +88,9 @@ public Interception SetInterceptorFor(Type typeToIntercept, ITypeInterceptor int
/// <param name="name">Name type is registered under.</param>
/// <param name="interceptor">Interceptor object to use.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetInterceptorFor<T>(string name, ITypeInterceptor interceptor)
{
return this.SetInterceptorFor(typeof(T), name, interceptor);
return SetInterceptorFor(typeof(T), name, interceptor);
}

/// <summary>
Expand All @@ -98,10 +99,9 @@ public Interception SetInterceptorFor<T>(string name, ITypeInterceptor intercept
/// <typeparam name="T">Type to intercept</typeparam>
/// <param name="interceptor">Interceptor object to use.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetInterceptorFor<T>(ITypeInterceptor interceptor)
{
return this.SetInterceptorFor(typeof(T), null, interceptor);
return SetInterceptorFor(typeof(T), null, interceptor);
}

/// <summary>
Expand Down Expand Up @@ -158,10 +158,9 @@ public Interception SetDefaultInterceptorFor(Type typeToIntercept, ITypeIntercep
/// <typeparam name="TTypeToIntercept">Type to intercept</typeparam>
/// <param name="interceptor">Interceptor instance.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetDefaultInterceptorFor<TTypeToIntercept>(ITypeInterceptor interceptor)
{
return this.SetDefaultInterceptorFor(typeof(TTypeToIntercept), interceptor);
return SetDefaultInterceptorFor(typeof(TTypeToIntercept), interceptor);
}

/// <summary>
Expand All @@ -172,7 +171,7 @@ public Interception SetDefaultInterceptorFor<TTypeToIntercept>(ITypeInterceptor
/// <returns>This extension object.</returns>
public Interception SetInterceptorFor(Type typeToIntercept, IInstanceInterceptor interceptor)
{
return this.SetInterceptorFor(typeToIntercept, null, interceptor);
return SetInterceptorFor(typeToIntercept, null, interceptor);
}

/// <summary>
Expand All @@ -182,10 +181,9 @@ public Interception SetInterceptorFor(Type typeToIntercept, IInstanceInterceptor
/// <param name="name">Name type is registered under.</param>
/// <param name="interceptor">Instance interceptor to use.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetInterceptorFor<T>(string name, IInstanceInterceptor interceptor)
{
return this.SetInterceptorFor(typeof(T), name, interceptor);
return SetInterceptorFor(typeof(T), name, interceptor);
}

/// <summary>
Expand All @@ -194,10 +192,9 @@ public Interception SetInterceptorFor<T>(string name, IInstanceInterceptor inter
/// <typeparam name="T">Type to intercept.</typeparam>
/// <param name="interceptor">Instance interceptor to use.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetInterceptorFor<T>(IInstanceInterceptor interceptor)
{
return this.SetInterceptorFor(typeof(T), null, interceptor);
return SetInterceptorFor(typeof(T), null, interceptor);
}

/// <summary>
Expand Down Expand Up @@ -228,10 +225,9 @@ public Interception SetDefaultInterceptorFor(Type typeToIntercept, IInstanceInte
/// <typeparam name="TTypeToIntercept">Type the interception is being configured for.</typeparam>
/// <param name="interceptor">The interceptor to use by default.</param>
/// <returns>This extension object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public Interception SetDefaultInterceptorFor<TTypeToIntercept>(IInstanceInterceptor interceptor)
{
return this.SetDefaultInterceptorFor(typeof(TTypeToIntercept), interceptor);
return SetDefaultInterceptorFor(typeof(TTypeToIntercept), interceptor);
}

private static void GuardTypeInterceptable(Type typeToIntercept, IInterceptor interceptor)
Expand All @@ -243,7 +239,7 @@ private static void GuardTypeInterceptable(Type typeToIntercept, IInterceptor in
CultureInfo.CurrentCulture,
Resources.InterceptionNotSupported,
typeToIntercept.FullName),
"typeToIntercept");
nameof(typeToIntercept));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ContainerIntegration/InterceptionBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System;
using Microsoft.Practices.ObjectBuilder2;
using Unity;
using Unity.Interception.ContainerIntegration.ObjectBuilder;
using Unity.Interception.InterceptionBehaviors;
using Unity.Policy;

namespace Microsoft.Practices.Unity.InterceptionExtension
namespace Unity.Interception.ContainerIntegration
{
/// <summary>
/// Stores information about a single <see cref="IInterceptionBehavior"/> to be used on an intercepted object and
Expand Down
Loading

0 comments on commit 7a99a90

Please sign in to comment.