//private object GetInstance(RegisteredObject registeredObject) //{ // object instance = registeredObject.SingletonInstance; // if (instance == null) // { // var parameters = ResolveConstructorParameters(registeredObject); // instance = registeredObject.CreateInstance(parameters.ToArray()); // } // return instance; //} private object GetInstance(RegisteredObject registeredObject) { object instance = registeredObject.Instance; if (instance == null) { var param = ResolveConstructorParameters(registeredObject); registeredObject.CreateInstance(param.ToArray()); instance = registeredObject.Instance; foreach (var properti in instance.GetType().GetProperties()) { if (properti.GetCustomAttribute(typeof(LabelAttr)) != null) { var paramType = properti.PropertyType; var obj = ResolveObject(paramType); properti.SetValue(instance, obj); } } //foreach (var method in instance.GetType().GetMethods()) //{ // if (method.GetCustomAttribute(typeof(LabelAttr)) != null) // { // var args = method.GetParameters(); // List<object> list = new List<object>(); // foreach (var arg in args) // { // var type = arg.ParameterType; // //var obj = Activator.CreateInstance(type); // var obj = ResolveObject(paramType); // list.Add(obj); // } // method?.Invoke(instance, list.ToArray()); // } //} } return(instance); }
private IEnumerable <object> ResolveConstructorParameters(RegisteredObject registeredObject) { var constructorInfo = registeredObject.ConcreteType.GetConstructors().First(); return(constructorInfo.GetParameters().Select(parameter => ResolveObject(parameter.ParameterType))); }