/// <summary> /// Determines if the component requires a target instance for proxying. /// </summary> /// <param name="kernel"> The kernel. </param> /// <param name="model"> The model. </param> /// <returns> true if an instance is required. </returns> public override bool RequiresTargetInstance(IKernel kernel, ComponentModel model) { var proxyOptions = model.ObtainProxyOptions(); return(model.HasClassServices == false && proxyOptions.OmitTarget == false); }
public override object Create(IKernel kernel, object instance, ComponentModel model, CreationContext context, params object[] constructorArguments) { var channelHolder = instance as IWcfChannelHolder; if (channelHolder == null) { throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance"); } if (channelHolder.RealProxy == null) { return(channelHolder.Channel); } if (model.Services.Count() > 1) { throw new ArgumentException(string.Format( "Component {0}, which was designated as a WCF proxy exposes {1} services. The facility currently only supports single-service components.", model.Name, model.Services.Count())); } var isDuplex = IsDuplex(channelHolder.RealProxy); var proxyOptions = model.ObtainProxyOptions(); var serviceContract = model.GetServiceContract(); var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context); var additionalInterfaces = GetInterfaces(model.Services, proxyOptions, isDuplex); var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context); return(generator.CreateInterfaceProxyWithTarget(typeof(IWcfChannelHolder), additionalInterfaces, channelHolder, generationOptions, interceptors)); }
public void ConfigureComponentModel(IKernel kernel, ComponentModel model) { if (model.HasInterceptors && model.Implementation.IsInterface) { var options = model.ObtainProxyOptions(); options.OmitTarget = true; } }
private void ConfigureProxyOptions(ComponentModel model) { if (controlProxyHook == null) { return; } var proxyOptions = model.ObtainProxyOptions(); proxyOptions.Hook = controlProxyHook; }
private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model) { var options = model.ObtainProxyOptions(); #if !SILVERLIGHT if (behavior.UseMarshalByRefProxy) { EnsureComponentRegisteredWithInterface(model); } options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy; #endif options.AddAdditionalInterfaces(behavior.AdditionalInterfaces); }
public void BuildComponentModel(IKernel kernel, ComponentModel model) { if (!mixIns.Any()) { return; } var options = model.ObtainProxyOptions(); foreach (var mixIn in mixIns) { options.AddMixinReference(mixIn); } }
/// <summary> /// Creates the proxy for the supplied component. /// </summary> /// <param name="kernel"> The kernel. </param> /// <param name="target"> The target. </param> /// <param name="model"> The model. </param> /// <param name="constructorArguments"> The constructor arguments. </param> /// <param name="context"> The creation context </param> /// <returns> The component proxy. </returns> public override object Create(IKernel kernel, object target, ComponentModel model, CreationContext context, params object[] constructorArguments) { object proxy; var interceptors = ObtainInterceptors(kernel, model, context); var proxyOptions = model.ObtainProxyOptions(); var proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions, kernel, context, model); CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments); var interfaces = proxyOptions.AdditionalInterfaces; if (model.HasClassServices == false) { var firstService = model.Services.First(); var additionalInterfaces = model.Services.Skip(1).Concat(interfaces).ToArray(); if (proxyOptions.OmitTarget) { proxy = generator.CreateInterfaceProxyWithoutTarget(firstService, additionalInterfaces, proxyGenOptions, interceptors); } else if (proxyOptions.AllowChangeTarget) { proxy = generator.CreateInterfaceProxyWithTargetInterface(firstService, additionalInterfaces, target, proxyGenOptions, interceptors); } else { proxy = generator.CreateInterfaceProxyWithTarget(firstService, additionalInterfaces, target, proxyGenOptions, interceptors); } } else { Type classToProxy; if (model.Implementation != null && model.Implementation != typeof(LateBoundComponent)) { classToProxy = model.Implementation; } else { classToProxy = model.Services.First(); } var additionalInterfaces = model.Services .SkipWhile(s => s.GetTypeInfo().IsClass) .Concat(interfaces) .ToArray(); proxy = generator.CreateClassProxy(classToProxy, additionalInterfaces, proxyGenOptions, constructorArguments, interceptors); } CustomizeProxy(proxy, proxyGenOptions, kernel, model); ReleaseHook(proxyGenOptions, kernel); return(proxy); }
public override object Create(IProxyFactoryExtension customFactory, IKernel kernel, ComponentModel model, CreationContext context, params object[] constructorArguments) { var interceptors = ObtainInterceptors(kernel, model, context); var proxyOptions = model.ObtainProxyOptions(); var proxyGenOptions = CreateProxyGenerationOptionsFrom(proxyOptions, kernel, context, model); CustomizeOptions(proxyGenOptions, kernel, model, constructorArguments); var builder = generator.ProxyBuilder; var proxy = customFactory.Generate(builder, proxyGenOptions, interceptors, model, context); CustomizeProxy(proxy, proxyGenOptions, kernel, model); ReleaseHook(proxyGenOptions, kernel); return(proxy); }
public void AddTypedFactoryEntry(FactoryEntry entry) { var model = new ComponentModel(new ComponentName(entry.Id, true), new[] { entry.FactoryInterface }, typeof(Empty), new Arguments().Insert("typed.fac.entry", entry)) { LifestyleType = LifestyleType.Singleton }; model.Interceptors.Add(new InterceptorReference(typeof(FactoryInterceptor))); var proxyOptions = model.ObtainProxyOptions(); proxyOptions.OmitTarget = true; ((IKernelInternal)Kernel).AddCustomComponent(model); }
private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model) { var options = model.ObtainProxyOptions(); #if FEATURE_REMOTING if (behavior.UseMarshalByRefProxy) { EnsureComponentRegisteredWithInterface(model); } options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy; #endif options.AddAdditionalInterfaces(behavior.AdditionalInterfaces); if (model.Implementation.GetTypeInfo().IsInterface) { options.OmitTarget = true; } }
protected virtual void CollectFromConfiguration(ComponentModel model) { if (model.Configuration == null) { return; } var interceptors = model.Configuration.Children["interceptors"]; if (interceptors == null) { return; } CollectInterceptors(model, interceptors); var options = model.ObtainProxyOptions(); CollectSelector(interceptors, options); CollectHook(interceptors, options); }
public bool ShouldCreateProxy(ComponentModel model) { if (model.HasInterceptors) { return(true); } var options = model.ObtainProxyOptions(false); if (options != null && options.RequiresProxy) { return(true); } if (selectors != null && selectors.Any(s => s.HasInterceptors(model))) { return(true); } return(false); }
public void ProcessModel(IKernel kernel, ComponentModel model) { Pointcut.ApplyInterceptor(model); var proxyOptions = model.ObtainProxyOptions(); if (proxyOptions.Selector == null) { proxyOptions.Selector = new InstanceReference <CoreInterceptorSelector>(new CoreInterceptorSelector(Pointcut)); } else { try { proxyOptions.Selector = new InstanceReference <CoreInterceptorSelector>(new CoreInterceptorSelector(proxyOptions.Selector.Resolve(kernel, null), Pointcut)); } catch (Exception e) { throw new Exception("can not change ProxyOptions selector for type : " + model.Name, e); } } }
/// <summary> /// Applies the synchronization support to the model. /// </summary> /// <param name = "model">The model.</param> /// <param name = "kernel">The kernel.</param> private void ApplySynchronization(ComponentModel model, IKernel kernel) { var options = model.ObtainProxyOptions(); model.Interceptors.Add(new InterceptorReference(typeof(SynchronizeInterceptor))); var metaInfo = metaStore.GetMetaFor(model.Implementation); if (metaInfo != null) { IInterceptorSelector userSelector = null; if (options.Selector != null) { userSelector = options.Selector.Resolve(kernel, CreationContext.CreateEmpty()); } options.Selector = new InstanceReference <IInterceptorSelector>(new SynchronizeInterceptorSelector(metaInfo, userSelector)); foreach (var reference in metaInfo.GetUniqueSynchContextReferences()) { reference.Attach(model); } } }
public override object Create(IKernel kernel, object instance, ComponentModel model, CreationContext context, params object[] constructorArguments) { var channelHolder = instance as IWcfChannelHolder; if (channelHolder == null) { throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance"); } var isDuplex = IsDuplex(channelHolder.RealProxy); var proxyOptions = model.ObtainProxyOptions(); var serviceContract = model.GetServiceContract(); var remainingServices = model.Services.Except(new[] { serviceContract }); var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context); generationOptions.AddMixinInstance(channelHolder); var additionalInterfaces = GetInterfaces(remainingServices, proxyOptions, isDuplex); var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context); return(generator.CreateInterfaceProxyWithTargetInterface(serviceContract, additionalInterfaces, channelHolder.Channel, generationOptions, interceptors)); }
public void ProcessModel(IKernel kernel, ComponentModel model) { if (model.Configuration == null) { return; } var mixins = model.Configuration.Children["mixins"]; if (mixins == null) { return; } var mixinReferences = new List <ComponentReference <object> >(); foreach (var mixin in mixins.Children) { var value = mixin.Value; var mixinComponent = ReferenceExpressionUtil.ExtractComponentName(value); if (mixinComponent == null) { throw new Exception( String.Format("The value for the mixin must be a reference to a component (Currently {0})", value)); } mixinReferences.Add(new ComponentReference <object>(mixinComponent)); } if (mixinReferences.Count == 0) { return; } var options = model.ObtainProxyOptions(); mixinReferences.ForEach(options.AddMixinReference); }
public void BuildComponentModel(IKernel kernel, ComponentModel model) { var options = model.ObtainProxyOptions(); // ... do whatever you need to customise the proxy generation options }
public void BuildComponentModel(IKernel kernel, ComponentModel model) { var options = model.ObtainProxyOptions(); options.Hook = hook; }
public void BuildComponentModel(IKernel kernel, ComponentModel model) { var options = model.ObtainProxyOptions(); options.Selector = selector; }
public void BuildComponentModel(IKernel kernel, ComponentModel model) { var options = model.ObtainProxyOptions(); options.AddAdditionalInterfaces(interfaces); }