<commit_before>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using StructureMap.Building;
using StructureMap.Construction;
using StructureMap.Graph;
using StructureMap.TypeRules;

namespace StructureMap.Pipeline
{
    public class ConstructorInstance : Instance, IConfiguredInstance, IStructuredInstance
    {
        private readonly object _locker = new object();
        private readonly Type _pluggedType;
        private readonly DependencyCollection _dependencies = new DependencyCollection();

        [Obsolete("Going to eliminate the need for this")]
        private readonly Plugin _plugin;

        [Obsolete("Definitely eliminating this soon")]
        private volatile IInstanceBuilder _builder;

        public ConstructorInstance(Type pluggedType)
            : this(new Plugin(pluggedType))
        {
        }

        public ConstructorInstance(Plugin plugin)
        {
            _plugin = plugin;
            _pluggedType = plugin.PluggedType;

            _pluggedType.GetCustomAttributes(typeof (InstanceAttribute), false).OfType<InstanceAttribute>()
                        .Each(x => x.Alter(this));
        }

        public ConstructorInstance(Type pluggedType, string name)
            : this(pluggedType)
        {
            Name = name;
        }

        public Plugin Plugin
        {
            get { return _plugin; }
        }

        void IConfiguredInstance.SetChild(string name, Instance instance)
        {
            SetChild(name, instance);
        }

        public void SetValue(Type type, object value, CannotFindProperty cannotFind)
        {
            string name = _plugin.FindArgumentNameForType(type, cannotFind);
            if (name != null) SetValue(name, value);
        }

        void IConfiguredInstance.SetValue(string name, object value)
        {
            SetValue(name, value);
        }

        void IConfiguredInstance.SetCollection(string name, IEnumerable<Instance> children)
        {
            SetCollection(name, children);
        }

        // Seems to exist only for testing the Xml configuration
        public string GetProperty(string propertyName)
        {
            var value = _dependencies.FindByTypeOrName(null, propertyName);
            return value == null ? null : value.ToString();
        }

        [Obsolete("Expose the dependencies instead")]
        public object Get(string propertyName, Type pluginType, BuildSession session)
        {
            var value = _dependencies.FindByTypeOrName(pluginType, propertyName);

            if (value == null) return new DefaultInstance().Build(pluginType, session);

            return value is Instance ? value.As<Instance>().Build(pluginType, session) : value;
        }

        [Obsolete("Seems to only be used in testing and for the Obsolete Argument")]
        public T Get<T>(string propertyName, BuildSession session)
        {<commit_msg>checkpoint: fixed an issue with the way ConstructorInstance was retrieving its own dependencies that was breaking tests<commit_after>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using StructureMap.Building;
using StructureMap.Construction;
using StructureMap.Graph;
using StructureMap.TypeRules;

namespace StructureMap.Pipeline
{
    public class ConstructorInstance : Instance, IConfiguredInstance, IStructuredInstance
    {
        private readonly object _locker = new object();
        private readonly Type _pluggedType;
        private readonly DependencyCollection _dependencies = new DependencyCollection();

        [Obsolete("Going to eliminate the need for this")]
        private readonly Plugin _plugin;

        [Obsolete("Definitely eliminating this soon")]
        private volatile IInstanceBuilder _builder;

        public ConstructorInstance(Type pluggedType)
            : this(new Plugin(pluggedType))
        {
        }

        public ConstructorInstance(Plugin plugin)
        {
            _plugin = plugin;
            _pluggedType = plugin.PluggedType;

            _pluggedType.GetCustomAttributes(typeof (InstanceAttribute), false).OfType<InstanceAttribute>()
                        .Each(x => x.Alter(this));
        }

        public ConstructorInstance(Type pluggedType, string name)
            : this(pluggedType)
        {
            Name = name;
        }

        public Plugin Plugin
        {
            get { return _plugin; }
        }

        void IConfiguredInstance.SetChild(string name, Instance instance)
        {
            SetChild(name, instance);
        }

        public void SetValue(Type type, object value, CannotFindProperty cannotFind)
        {
            string name = _plugin.FindArgumentNameForType(type, cannotFind);
            if (name != null) SetValue(name, value);
        }

        void IConfiguredInstance.SetValue(string name, object value)
        {
            SetValue(name, value);
        }

        void IConfiguredInstance.SetCollection(string name, IEnumerable<Instance> children)
        {
            SetCollection(name, children);
        }

        // Seems to exist only for testing the Xml configuration
        [Obsolete("Get rid of this when we can expose the Dependencies")]
        public string GetProperty(string propertyName)
        {
            var value = _dependencies.FindByTypeOrName(null, propertyName);

            if (value is ObjectInstance)
            {
                return value.As<ObjectInstance>().Object.ToString();
            }

            return value == null ? null : value.ToString();
        }

        [Obsolete("Expose the dependencies instead")]
        public object Get(string propertyName, Type pluginType, BuildSession session)
        {
            var value = _dependencies.FindByTypeOrName(pluginType, propertyName);

            if (value == null) return new DefaultInstance().Build(pluginType, session);

            return value is Instance ? value.As<Instance>().Build(pluginType, session) : value;
        }

        [Obsolete("Seems to only be used in testing and for the Obsolete Argument")]
        public T Get<T>(string propertyName, BuildSession session)
        {
{'fraction_non_alphanumeric': 0.07612511969358442, 'fraction_numerical': 0.0, 'mean_word_length': 2.4434065934065936, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4885128', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1472, 'n_words': 432}