|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 4 | +using Unity.Interception.InterceptionBehaviors; |
| 5 | +using Unity.Interception.Interceptors.InstanceInterceptors.InterfaceInterception; |
| 6 | +using Unity.Interception.PolicyInjection.Pipeline; |
| 7 | +using Unity.Interception.ContainerIntegration; |
| 8 | +using Unity.Lifetime; |
| 9 | +using System.Diagnostics; |
| 10 | + |
| 11 | +namespace Unity.Interception.Tests |
| 12 | +{ |
| 13 | + [TestClass] |
| 14 | + public class Issues |
| 15 | + { |
| 16 | + [TestMethod] |
| 17 | + public void unitycontainer_interception_162() |
| 18 | + { |
| 19 | + var container = new UnityContainer(); |
| 20 | + container.AddNewExtension<Interception>(); |
| 21 | + container.RegisterType<IMyClass, MyClass>(new ContainerControlledLifetimeManager(), |
| 22 | + new Interceptor<InterfaceInterceptor>(), |
| 23 | + new InterceptionBehavior<LoggingInterceptionBehavior>()); |
| 24 | + |
| 25 | + var class1 = container.Resolve<IMyClass>(); |
| 26 | + var class2 = container.Resolve<IMyClass>(); |
| 27 | + class1.MyFunction(); |
| 28 | + class2.MyFunction(); |
| 29 | + } |
| 30 | + |
| 31 | + public interface IMyClass { void MyFunction(); } |
| 32 | + public class MyClass : IMyClass |
| 33 | + { |
| 34 | + public MyClass() { Debug.WriteLine("Create MyClass"); } |
| 35 | + public void MyFunction() { Debug.WriteLine("Function of MyClass"); } |
| 36 | + } |
| 37 | + public class LoggingInterceptionBehavior : IInterceptionBehavior |
| 38 | + { |
| 39 | + public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) |
| 40 | + { |
| 41 | + Debug.WriteLine("Logging before the Function!! yeah, i like it!"); |
| 42 | + return getNext()(input, getNext); |
| 43 | + } |
| 44 | + |
| 45 | + public bool WillExecute => true; |
| 46 | + public IEnumerable<Type> GetRequiredInterfaces() { return Type.EmptyTypes; } |
| 47 | + } |
| 48 | + |
| 49 | + } |
| 50 | +} |
0 commit comments