public void Compose_should_select_first_result_in_GetService() { var value1 = new Exception(); var value2 = new Exception(); var sp1 = ServiceProvider.FromValue(value1); var sp2 = ServiceProvider.FromValue(value2); var sp = ServiceProvider.Compose(sp1, sp2); Assert.Same(value1, sp.GetService(typeof(Exception))); }
private void DoPropertyBind(PropertyTreeMetaObject target, PropertyTreeNavigator navigator, PropertyDefinition property) { object ancestor = null; PropertyTreeMetaObject ancestorMeta = null; if (property.IsExtender) { var ancestorType = property.DeclaringTreeDefinition.SourceClrType; ancestorMeta = target.Ancestors.FirstOrDefault( t => ancestorType.IsAssignableFrom(t.ComponentType)); if (ancestorMeta != null) { ancestor = ancestorMeta.Component; } } var component = target.Component; PropertyTreeMetaObject propertyTarget = target.CreateChild(property, navigator.QualifiedName, ancestorMeta); var services = new PropertyBindContext( component, property, ServiceProvider.Compose(ServiceProvider.FromValue(navigator), this)) { LineNumber = navigator.LineNumber, LinePosition = navigator.LinePosition, }; try { propertyTarget = Bind(propertyTarget, navigator, services); target.BindSetMember(property, navigator.QualifiedName, propertyTarget, ancestorMeta, services); } catch (NullReferenceException nre) { // Normally a "critical" exception, consider it a conversion error _errors.BinderConversionError(property.Name, target.ComponentType, nre, navigator.FileLocation); } catch (ArgumentException a) { _errors.BinderConversionError(property.Name, target.ComponentType, a, navigator.FileLocation); } catch (PropertyTreeException) { throw; } catch (Exception ex) { if (ex.IsCriticalException()) { throw; } _errors.BinderConversionError(property.Name, target.ComponentType, ex, navigator.FileLocation); } }
private PropertyTreeMetaObject BindInitializeValue(PropertyTreeMetaObject target, PropertyTreeNavigator navigator, IServiceProvider serviceProvider, Func <PropertyTreeMetaObject> thunk) { try { return(thunk()); } catch (PropertyTreeException) { throw; } catch (Exception ex) { var sp = ServiceProvider.Compose(ServiceProvider.FromValue(navigator), serviceProvider, this); // Throw critical exceptions if they originate within PT; otherwise, allow // callback to decide how to handle them. if (ex.IsCriticalException()) { throw; } var descriptor = serviceProvider.GetServiceOrDefault <IValueSerializerContext>(); string property = navigator.QualifiedName.ToString(); Type componentType; if (descriptor == null || descriptor.Instance == null) { componentType = target.ComponentType; } else if (descriptor.Property == null) { componentType = descriptor.Instance.GetType(); } else { property = descriptor.Property.Name; componentType = descriptor.Property.DeclaringType; } FileLocation loc = navigator.FileLocation; object value = navigator.Value; _errors.BinderConversionError(property, componentType, ex, loc); } return(target); }
public void Render(DomElement element, HxlWriter output) { var eti = new HxlElementTemplateInfo(element.Name, element.Attribute("class")); var services = ServiceProvider.Compose( ServiceProvider.Current, ServiceProvider.FromValue(eti)); var template = output.TemplateContext.TemplateFactory.CreateTemplate(_name, _type, services); if (template == null) { // TODO Missing line number throw HxlFailure.CannotFindMatchingTemplate(_type, _name, -1, -1); } var context = output.TemplateContext.CreateChildContext(template); context.Data.Add("element", element); template.Transform(output.BaseWriter, context); }
// IActivationFactory implementation public virtual object CreateInstance( Type type, IEnumerable <KeyValuePair <string, object> > values = null, IServiceProvider serviceProvider = null, params Attribute[] attributes) { IServiceProvider actualServiceProvider; if (serviceProvider == this) { actualServiceProvider = serviceProvider; } else if (serviceProvider == null) { actualServiceProvider = this; } else { actualServiceProvider = ServiceProvider.Compose(serviceProvider, this); } return(_activationFactory.CreateInstance(type, values, actualServiceProvider, attributes)); }
internal IServiceProvider GetBasicServices(PropertyTreeNavigator nav) { return(ServiceProvider.Compose(this, ServiceProvider.FromValue(nav))); }
public void Compose_should_return_null_on_null_instances() { var sp = ServiceProvider.Compose(null, null, null); Assert.Same(ServiceProvider.Null, sp); }
public void Compose_should_return_null_on_empty_list() { var sp = ServiceProvider.Compose(Enumerable.Empty <IServiceProvider>()); Assert.Same(ServiceProvider.Null, sp); }