private DependencyResolution ResolveDependencyByServiceLocation(string parameterName, Type parameterType) { if (parameterType.IsArray) { Type elementType = parameterType.GetElementType(); if (ComponentHandle.IsComponentHandleType(elementType)) { Type serviceType = GetServiceTypeFromComponentHandleType(elementType); if (serviceLocator.HasService(serviceType)) { IList <ComponentHandle> componentHandles = serviceLocator.ResolveAllHandles(serviceType); return(DependencyResolution.Satisfied(CreateArray(elementType, componentHandles))); } } else { Type serviceType = elementType; if (serviceLocator.HasService(serviceType)) { IList <object> components = serviceLocator.ResolveAll(serviceType); return(DependencyResolution.Satisfied(CreateArray(serviceType, components))); } } } else { if (ComponentHandle.IsComponentHandleType(parameterType)) { Type serviceType = GetServiceTypeFromComponentHandleType(parameterType); if (serviceLocator.HasService(serviceType)) { ComponentHandle componentHandle = serviceLocator.ResolveHandle(serviceType); return(DependencyResolution.Satisfied(componentHandle)); } } else { Type serviceType = parameterType; if (serviceLocator.HasService(serviceType)) { object component = serviceLocator.Resolve(parameterType); return(DependencyResolution.Satisfied(component)); } } } return(DependencyResolution.Unsatisfied()); }
public override DependencyResolution ResolveDependency(string parameterName, Type parameterType, string configurationArgument) { if (configurationArgument == null) { if (typeof(Traits).IsAssignableFrom(parameterType) && // check we want traits parameterType.IsAssignableFrom(typeof(PluginTraits))) // check we can handle the traits { return(DependencyResolution.Satisfied(descriptor.ResolveTraits())); } if (parameterType == typeof(IPluginDescriptor)) { return(DependencyResolution.Satisfied(descriptor)); } } return(base.ResolveDependency(parameterName, parameterType, configurationArgument)); }
private DependencyResolution ResolveDependencyByConfiguration(string parameterName, Type parameterType, string configurationArgument) { configurationArgument = configurationArgument.Trim(); if (parameterType.IsArray) { // TODO: Should really provide a better way to extract structural information from the configuration argument. Type type = parameterType.GetElementType(); object[] values = Array.ConvertAll(configurationArgument.Split(';'), value => ConvertConfigurationArgumentToType(type, value)); return(DependencyResolution.Satisfied(CreateArray(type, values))); } else { object value = ConvertConfigurationArgumentToType(parameterType, configurationArgument); return(DependencyResolution.Satisfied(value)); } }
public override DependencyResolution ResolveDependency(string parameterName, Type parameterType, string configurationArgument) { if (configurationArgument == null) { if (typeof(Traits).IsAssignableFrom(parameterType) && // check we want traits (fast, do this first) parameterType.IsAssignableFrom(descriptor.serviceDescriptor.ResolveTraitsType())) // confirm we can handle the traits (slow) { return(DependencyResolution.Satisfied(descriptor.ResolveTraits())); } if (parameterType == typeof(IComponentDescriptor)) { return(DependencyResolution.Satisfied(descriptor)); } } return(base.ResolveDependency(parameterName, parameterType, configurationArgument)); }