/// <summary> /// Obtains the <see cref = "ProxyOptions" /> associated with the <see cref = "ComponentModel" />. /// </summary> /// <param name = "model">The component model.</param> /// <param name = "createOnDemand">true if the options should be created if not present.</param> /// <returns>The associated proxy options for the component model.</returns> public static ProxyOptions ObtainProxyOptions(this ComponentModel model, bool createOnDemand = true) { var options = model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] as ProxyOptions; if (options == null && createOnDemand) { options = new ProxyOptions(model); model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] = options; } return options; }
/// <summary> /// Obtains the <see cref = "ProxyOptions" /> associated with the <see cref = "ComponentModel" />. /// </summary> /// <param name = "model">The component model.</param> /// <param name = "createOnDemand">true if the options should be created if not present.</param> /// <returns>The associated proxy options for the component model.</returns> public static ProxyOptions ObtainProxyOptions(ComponentModel model, bool createOnDemand) { var options = model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] as ProxyOptions; if (options == null && createOnDemand) { options = new ProxyOptions(model); model.ExtendedProperties[ProxyConstants.ProxyOptionsKey] = options; } return(options); }
protected virtual Type[] GetInterfaces(Type service, ProxyOptions proxyOptions, bool isDuplex) { var additionalInterfaces = proxyOptions.AdditionalInterfaces ?? Type.EmptyTypes; Array.Resize(ref additionalInterfaces, additionalInterfaces.Length + (isDuplex ? 4 : 3)); int index = additionalInterfaces.Length; additionalInterfaces[--index] = service; additionalInterfaces[--index] = typeof(IServiceChannel); additionalInterfaces[--index] = typeof(IClientChannel); if (isDuplex) additionalInterfaces[--index] = typeof(IDuplexContextChannel); return additionalInterfaces; }
protected virtual Type[] GetInterfaces(IEnumerable<Type> services, ProxyOptions proxyOptions, bool isDuplex) { var interfaces = services.ToList(); if (proxyOptions.AdditionalInterfaces != null) { interfaces.AddRange(proxyOptions.AdditionalInterfaces); } interfaces.Add(typeof(IServiceChannel)); interfaces.Add(typeof(IClientChannel)); if (isDuplex) { interfaces.Add(typeof(IDuplexContextChannel)); } return interfaces.ToArray(); }
protected virtual void CollectHook(IConfiguration interceptors, ProxyOptions options) { var hook = interceptors.Attributes["hook"]; if (hook == null) { return; } if (!ReferenceExpressionUtil.IsReference(hook)) { throw new Exception( String.Format("The value for the hook must be a reference to a component (Currently {0})", hook)); } var componentKey = ReferenceExpressionUtil.ExtractComponentKey(hook); options.Hook = new ComponentReference<IProxyGenerationHook>(componentKey); }
protected virtual void CollectSelector(IConfiguration interceptors, ProxyOptions options) { var selector = interceptors.Attributes["selector"]; if (selector == null) { return; } if (!ReferenceExpressionUtil.IsReference(selector)) { throw new Exception( String.Format("The value for the selector must be a reference to a component (Currently {0})", selector)); } var componentKey = ReferenceExpressionUtil.ExtractComponentKey(selector); options.Selector = new ComponentReference<IInterceptorSelector>(componentKey); }
private bool MixInsAreEquals(ProxyOptions proxyOptions) { if (!Equals(mixInList == null, proxyOptions.mixInList == null)) { return(false); } if (mixInList == null) { return(true); //both are null, nothing more to check } if (mixInList.Count != proxyOptions.mixInList.Count) { return(false); } for (var i = 0; i < mixInList.Count; ++i) { if (!proxyOptions.mixInList.Contains(mixInList[i])) { return(false); } } return(true); }
private bool AdditionalInterfacesAreEquals(ProxyOptions proxyOptions) { if (!Equals(interfaceList == null, proxyOptions.interfaceList == null)) { return(false); } if (interfaceList == null) { return(true); //both are null, nothing more to check } if (interfaceList.Count != proxyOptions.interfaceList.Count) { return(false); } for (var i = 0; i < interfaceList.Count; ++i) { if (!proxyOptions.interfaceList.Contains(interfaceList[i])) { return(false); } } return(true); }
protected static ProxyGenerationOptions CreateProxyGenerationOptionsFrom(ProxyOptions proxyOptions, IKernel kernel, CreationContext context, ComponentModel model) { var proxyGenOptions = new ProxyGenerationOptions(); if (proxyOptions.Hook != null) { var hook = proxyOptions.Hook.Resolve(kernel, context); if(hook != null && hook is IOnBehalfAware) { ((IOnBehalfAware)hook).SetInterceptedComponentModel(model); } proxyGenOptions.Hook = hook; } if (proxyOptions.Selector != null) { var selector = proxyOptions.Selector.Resolve(kernel, context); if (selector != null && selector is IOnBehalfAware) { ((IOnBehalfAware)selector).SetInterceptedComponentModel(model); } proxyGenOptions.Selector = selector; } #if (!SILVERLIGHT) if (proxyOptions.UseMarshalByRefAsBaseClass) { proxyGenOptions.BaseTypeForInterfaceProxy = typeof(MarshalByRefObject); } #endif foreach (var mixInReference in proxyOptions.MixIns) { var mixIn = mixInReference.Resolve(kernel, context); proxyGenOptions.AddMixinInstance(mixIn); } return proxyGenOptions; }
protected static ProxyGenerationOptions CreateProxyGenerationOptionsFrom(ProxyOptions proxyOptions, IKernel kernel, CreationContext context) { var proxyGenOptions = new ProxyGenerationOptions(); if (proxyOptions.Hook != null) { var hook = proxyOptions.Hook.Resolve(kernel, context); proxyGenOptions.Hook = hook; } if (proxyOptions.Selector != null) { var selector = proxyOptions.Selector.Resolve(kernel, context); proxyGenOptions.Selector = selector; } #if (!SILVERLIGHT) if (proxyOptions.UseMarshalByRefAsBaseClass) { proxyGenOptions.BaseTypeForInterfaceProxy = typeof(MarshalByRefObject); } #endif foreach (var mixInReference in proxyOptions.MixIns) { var mixIn = mixInReference.Resolve(kernel, context); proxyGenOptions.AddMixinInstance(mixIn); } return proxyGenOptions; }
protected static ProxyGenerationOptions CreateProxyGenerationOptionsFrom(ProxyOptions proxyOptions) { ProxyGenerationOptions proxyGenOptions = new ProxyGenerationOptions(); if (proxyOptions.Hook != null) { proxyGenOptions.Hook = new ProxyGenerationHookAdapter(proxyOptions.Hook); } if (proxyOptions.UseMarshalByRefAsBaseClass) { proxyGenOptions.BaseTypeForInterfaceProxy = typeof(MarshalByRefObject); } foreach (object mixIn in proxyOptions.MixIns) { proxyGenOptions.AddMixinInstance(mixIn); } return proxyGenOptions; }
private ProxyGenerationOptions CreateProxyGenerationOptions(Type service, ProxyOptions proxyOptions, IKernel kernel, CreationContext context) { var userProvidedSelector = (proxyOptions.Selector != null) ? proxyOptions.Selector.Resolve(kernel, context) : null; var proxyGenOptions = new ProxyGenerationOptions(wcfProxyGenerationHook) { Selector = new WcfInterceptorSelector(service, userProvidedSelector) }; if (proxyOptions.MixIns != null) { foreach (IReference<object> mixInReference in proxyOptions.MixIns) { var mixIn = mixInReference.Resolve(kernel, context); proxyGenOptions.AddMixinInstance(mixIn); } } return proxyGenOptions; }
private bool AdditionalInterfacesAreEquals(ProxyOptions proxyOptions) { if (!Equals(interfaceList == null, proxyOptions.interfaceList == null)) return false; if (interfaceList == null) return true; //both are null, nothing more to check if (interfaceList.Count != proxyOptions.interfaceList.Count) return false; for (int i = 0; i < interfaceList.Count; ++i) { if (!proxyOptions.interfaceList.Contains(interfaceList[0])) return false; } return true; }
private ProxyGenerationOptions CreateProxyGenerationOptions(Type service, ProxyOptions proxyOptions, IKernel kernel, CreationContext context) { if (proxyOptions.MixIns != null && proxyOptions.MixIns.Count() > 0) { throw new NotImplementedException("Support for mixins is not yet implemented. How about contributing a patch?"); } var userProvidedSelector = (proxyOptions.Selector != null) ? proxyOptions.Selector.Resolve(kernel, context) : null; var proxyGenOptions = new ProxyGenerationOptions(wcfProxyGenerationHook) { Selector = new WcfInterceptorSelector(service, userProvidedSelector) }; return proxyGenOptions; }
protected virtual Type[] GetInterfaces(Type service, ProxyOptions proxyOptions, bool isDuplex) { // TODO: this should be static and happen in IContributeComponentModelConstruction preferably var additionalInterfaces = proxyOptions.AdditionalInterfaces ?? Type.EmptyTypes; Array.Resize(ref additionalInterfaces, additionalInterfaces.Length + (isDuplex ? 4 : 3)); int index = additionalInterfaces.Length; additionalInterfaces[--index] = service; additionalInterfaces[--index] = typeof(IServiceChannel); additionalInterfaces[--index] = typeof(IClientChannel); if (isDuplex) additionalInterfaces[--index] = typeof(IDuplexContextChannel); return additionalInterfaces; }
private bool MixInsAreEquals(ProxyOptions proxyOptions) { if (!Equals(mixInList == null, proxyOptions.mixInList == null)) return false; if (mixInList == null) return true; //both are null, nothing more to check if (mixInList.Count != proxyOptions.mixInList.Count) return false; for (int i = 0; i < mixInList.Count; ++i) { if (!proxyOptions.mixInList.Contains(mixInList[0])) return false; } return true; }
private ProxyGenerationOptions CreateProxyGenerationOptions(Type service, ProxyOptions proxyOptions) { if (proxyOptions.MixIns != null && proxyOptions.MixIns.Length > 0) { throw new NotImplementedException( "Support for mixins is not yet implemented. How about contributing a patch?"); } var proxyGenOptions = new ProxyGenerationOptions(wcfProxyGenerationHook) { Selector = new WcfInterceptorSelector(service, proxyOptions.Selector) }; return proxyGenOptions; }