Advertisement
Guest User

UnityMemoryLeak

a guest
Dec 5th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. public class Program
  2.     {
  3.         public static void Main(string[] args)
  4.         {
  5.             using (var container = new UnityContainer())
  6.             {
  7.                 container.AddNewExtension<Interception>();
  8.  
  9.                 container.RegisterType<SimpleType>(
  10.                     new TransientLifetimeManager(),
  11.                     new Interceptor<VirtualMethodInterceptor>(),
  12.                     new InterceptionBehavior<SimpleInterceptor>());
  13.  
  14.                 while (true)
  15.                 {
  16.                     try
  17.                     {
  18.                         Console.ReadKey(true);
  19.  
  20.                         var type = container.Resolve<SimpleType>();
  21.                         container.Teardown(type);
  22.  
  23.                         Console.WriteLine("Take a snapshot...");
  24.                     }
  25.                     catch (Exception ex)
  26.                     {
  27.                         Console.WriteLine(ex.Message);
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.  
  33.         public class SimpleType
  34.         {
  35.         }
  36.  
  37.         public class SimpleInterceptor : IInterceptionBehavior
  38.         {
  39.             public bool WillExecute
  40.             {
  41.                 get
  42.                 {
  43.                     return true;
  44.                 }
  45.             }
  46.  
  47.             public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
  48.             {
  49.                 return getNext().Invoke(input, getNext);
  50.             }
  51.  
  52.             public IEnumerable<Type> GetRequiredInterfaces()
  53.             {
  54.                 return Type.EmptyTypes;
  55.             }
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement