Created
May 18, 2012 04:29
-
-
Save jpolvora/2723150 to your computer and use it in GitHub Desktop.
InterceptAllMethodsFromInterface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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