Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Created May 18, 2012 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpolvora/2723150 to your computer and use it in GitHub Desktop.
Save jpolvora/2723150 to your computer and use it in GitHub Desktop.
InterceptAllMethodsFromInterface
using System;
namespace DynamicProxy.Console.Infra
{
public interface IUnitOfWork : IDisposable
{
int SaveChanges();
}
}
public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("MyContext")
{
Configuration.AutoDetectChangesEnabled = false;
Configuration.LazyLoadingEnabled = false;
Configuration.ProxyCreationEnabled = false;
Configuration.ValidateOnSaveEnabled = false;
}
public IDbSet<Customer> Customers { get; set; }
}
static void InterceptAllMethodsFromInterface()
{
//will intercept all methods defined in the interface IUnitOfWork
var proxyCtx = ObjectProxyFactory.CreateUsingActions<IUnitOfWork>(new MyContext(),
pre =>
{
System.Console.WriteLine("Entering: {0}", pre.CallCtx.MethodName);
},
post =>
{
System.Console.WriteLine("Exiting: {0}", post.CallCtx.MethodName);
}, null, true, lambdas: null);
proxyCtx.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment