/// <summary> /// This method is called on ComponentRegistered event of Castle Windsor. /// </summary> public static void ComponentRegistered(string key, Castle.MicroKernel.IHandler handler) { if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { //Intercept all methods of all repositories. handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(NhUnitOfWorkInterceptor))); } else if (handler.ComponentModel.Implementation.GetMethods().Any(UnitOfWorkHelper.HasUnitOfWorkAttribute)) { //Intercept all methods of classes those have at least one method that has UnitOfWork attribute. //TODO: Intecept only UnitOfWork methods, not other methods! handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(NhUnitOfWorkInterceptor))); } }
private void KernelComponentRegistered(string key, IHandler handler) { if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add( new InterceptorReference(typeof(NHibernateUnitOfWorkInterceptor))); } if (handler.ComponentModel.Implementation.GetMethods().Any(UnitOfWorkHelper.HasUnitOfWorkAttribute)) { handler.ComponentModel.Interceptors.Add( new InterceptorReference(typeof(NHibernateUnitOfWorkInterceptor))); } }
public static void RegisterUnitOfWorkInterceptor(string key, IHandler handler) { foreach (var method in handler.ComponentModel.Implementation.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (UnitOfWorkHelper.HasUnitOfWorkAttribute(method)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); return; } } if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); return; } }
void Kernel_ComponentRegistered(string key, IHandler handler) { if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UoWInterceptor))); } foreach (var method in handler.ComponentModel.Implementation.GetMethods()) { if (UnitOfWorkHelper.HasUnitOfWorkAttribute(method)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UoWInterceptor))); return; } } }
private static void Kernel_ComponentRegistered(string key, IHandler handler) { if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(NHUnitOfWorkInterceptor))); } if ( !handler.ComponentModel.Implementation.GetMethods() .Any(method => UnitOfWorkHelper.HasUnitOfWorkAttribute(method))) { return; } handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(NHUnitOfWorkInterceptor))); }
static void Kernel_ComponentRegistered(string key, Castle.MicroKernel.IHandler handler) { //Intercept all methods of all repositories. if (UnitOfWorkHelper.IsRepositoryClass(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); } //Intercept all methods of classes those have at least one method that has UnitOfWork attribute. foreach (var method in handler.ComponentModel.Implementation.GetMethods()) { if (UnitOfWorkHelper.HasUnitOfWorkAttribute(method)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor))); return; } } }