public override INHibernateProxy GetProxy(object id, ISessionImplementor session) { INHibernateProxy proxy; try { var behaviorInfo = _behaviorConfigurator.GetProxyInformation(PersistentClass); var initializer = new LazyInitializer(EntityName, PersistentClass, id, GetIdentifierMethod, SetIdentifierMethod, ComponentIdType, session); IInterceptor[] interceptors = behaviorInfo.Interceptors .Select(i => _kernel.Resolve(i)) .OfType <IInterceptor>() .Union(new[] { initializer }).ToArray(); Type[] interfaces = Interfaces.Union(behaviorInfo.AdditionalInterfaces).ToArray(); object obj2 = IsClassProxy ? ProxyGenerator.CreateClassProxy(PersistentClass, interfaces, interceptors) : ProxyGenerator.CreateInterfaceProxyWithoutTarget(interfaces[0], interfaces, new IInterceptor[] { initializer }); initializer._constructed = true; proxy = (INHibernateProxy)obj2; } catch (Exception exception) { log.Error("Creating a proxy instance failed", exception); throw new HibernateException("Creating a proxy instance failed", exception); } return(proxy); }
public object GetEntity(Type type) { var proxyInfo = _behaviorConfigurator.GetProxyInformation(type); Type[] additionalInterfacesToProxy = proxyInfo.AdditionalInterfaces.ToArray(); IInterceptor[] interceptors = proxyInfo.Interceptors.Select(i => _kernel.Resolve(i)).OfType <IInterceptor>().ToArray(); if (interceptors.Length > 0) { object instance = proxyGenerator.CreateClassProxy(proxyInfo.EntityType, additionalInterfacesToProxy, interceptors); return(instance); } return(Activator.CreateInstance(type)); }
static void SetProxyInformation(ComponentModel model, IBehaviorConfigurator behaviorConfigurator) { var proxyInfo = behaviorConfigurator.GetProxyInformation(model.Implementation); //No proxy info. if (proxyInfo.AdditionalInterfaces.Count == 0 && proxyInfo.Interceptors.Count == 0) return; //apply interceptor references to the model foreach (var interceptorType in proxyInfo.Interceptors) { model.Dependencies.Add(new DependencyModel(DependencyType.Service, null, interceptorType, false)); model.Interceptors.Add(new InterceptorReference(interceptorType)); } //apply additional interfaces ProxyUtil.ObtainProxyOptions(model, true) .AddAdditionalInterfaces(proxyInfo.AdditionalInterfaces.ToArray()); }
static void SetProxyInformation(ComponentModel model, IBehaviorConfigurator behaviorConfigurator) { var proxyInfo = behaviorConfigurator.GetProxyInformation(model.Implementation); //No proxy info. if (proxyInfo.AdditionalInterfaces.Count == 0 && proxyInfo.Interceptors.Count == 0) { return; } //apply interceptor references to the model foreach (var interceptorType in proxyInfo.Interceptors) { model.Dependencies.Add(new DependencyModel(DependencyType.Service, null, interceptorType, false)); model.Interceptors.Add(new InterceptorReference(interceptorType)); } //apply additional interfaces ProxyUtil.ObtainProxyOptions(model, true) .AddAdditionalInterfaces(proxyInfo.AdditionalInterfaces.ToArray()); }