private static void RegisterInterceptor(ConfigurationExpression r, ProxyGenerator pg) { r.For <ICalculator>().Transient().Use <Calculator>() .EnrichWith(c => pg.CreateInterfaceProxyWithTarget <ICalculator>(c, new StructureMapInterceptionLogger())); }
public ITimeHelper Fix(ITimeHelper item) { return((ITimeHelper)_generator.CreateInterfaceProxyWithTarget(typeof(ITimeHelper), item, _options)); }
private static T MakeProxy(T instance) { var proxyGenerator = new ProxyGenerator(); return(proxyGenerator.CreateInterfaceProxyWithTarget(instance)); }
public static T CreateCastleInterfaceProxy <T>(T target) where T : class { Castle.DynamicProxy.ProxyGenerator generator = new ProxyGenerator(); return(generator.CreateInterfaceProxyWithTarget(target, new CastleInterceptor())); }
public Interface CreateProxyFor <Interface>(Interface target, params IInterceptor[] interceptors) where Interface : class { return(generator.CreateInterfaceProxyWithTarget(target, interceptors)); }
public ChangeTrackingFuncInterceptor(ProxyGenerator proxy) : base(x => proxy.CreateInterfaceProxyWithTarget(x, new ChangeTrackingInterceptor())) { }
/// <summary> /// Gets the interface proxy. /// </summary> /// <typeparam name="TInterface">The type of the interface.</typeparam> /// <param name="target">The target to generate to proxy for.</param> /// <param name="proxyGenerationHook">The proxy generation hook.</param> /// <param name="interceptors">The interceptors.</param> /// <returns> /// An proxy from the interface with the type <see cref="TInterface"/>. /// </returns> public static TInterface GetInterfaceProxy <TInterface>(TInterface target, IProxyGenerationHook proxyGenerationHook, params IInterceptor[] interceptors) { return((TInterface)proxyGenerator.CreateInterfaceProxyWithTarget(typeof(TInterface), target, new ProxyGenerationOptions(proxyGenerationHook), interceptors)); }
static void Main(string[] args) { IBookService bookService; var generator = new ProxyGenerator(); bookService = generator.CreateInterfaceProxyWithTarget <IBookService>( new BookService(), new Logger()); int option; do { Console.Write("\n"); Console.WriteLine("1. Add book"); Console.WriteLine("2. Get book list"); Console.WriteLine("3. Delete book by id"); Console.WriteLine("4. Exit"); Console.Write("\n" + "Please enter command: "); string userInput = Console.ReadLine(); if (int.TryParse(userInput, out option) && option > 0 && option < 5) { switch (option) { case 1: Console.WriteLine("Enter name:"); string bookName = Console.ReadLine(); Console.WriteLine("Enter author:"); string bookAuthor = Console.ReadLine(); Book book = new Book(bookName, bookAuthor); bookService.AddBook(book); break; case 2: var books = bookService.GetBooks(); foreach (var item in books) { Console.WriteLine("Id is " + item.Id + " author is " + item.Author + " name is " + item.Name); } break; case 3: Console.WriteLine("Enter book id:"); string input = Console.ReadLine(); if (int.TryParse(input, out var bookId)) { bookService.DeleteBook(bookId); } else { Console.WriteLine("The id is invalid"); } break; case 4: return; } } else { Console.WriteLine("The command is invalid"); } } while (option != 4); Console.ReadLine(); }