Ejemplo n.º 1
0
            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));
            }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        private Dictionary <PropertyInfo, object> ResolveOptionalDependencies()
        {
            var optionalDependencies = new Dictionary <PropertyInfo, object>();

            foreach (PropertyInfo property in objectType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                if (IsOptionalDependency(property))
                {
                    DependencyResolution dependencyResolution = ResolveDependency(property.Name, property.PropertyType, true);
                    if (dependencyResolution.IsSatisfied)
                    {
                        optionalDependencies.Add(property, dependencyResolution.Value);
                    }
                }
            }

            return(optionalDependencies);
        }
Ejemplo n.º 4
0
            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));
            }