示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
		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());
		}
示例#4
0
        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());
        }