コード例 #1
0
        public object CreateImplementation(Dependancy dependancy, Func <Type, object> factory)
        {
            if (dependancy.Implemented)
            {
                return(dependancy.Implementation);
            }

            object implementation = factory(dependancy.Type);

            if (dependancy.Lifetimes == DependancyLifetimes.Transient)
            {
                dependancy.AddImplementaion(implementation);
            }
            return(implementation);
        }
コード例 #2
0
        private object GetService(Type type)
        {
            Dependancy      dependancy  = _container.GetDependancy(type);
            ConstructorInfo constructor = dependancy.Type.GetConstructors().Single();

            ParameterInfo[] parameters = constructor.GetParameters().ToArray();

            if (parameters.Length > 0)
            {
                object[] parameterImplementations = new object[parameters.Length];

                for (int i = 0; i < parameters.Length; i++)
                {
                    parameterImplementations[i] = GetService(parameters[i].ParameterType);
                }

                return(CreateImplementation(dependancy, t => Activator.CreateInstance(t, parameterImplementations)));
            }
            return(CreateImplementation(dependancy, t => Activator.CreateInstance(t)));
        }