Esempio n. 1
0
        private void InjectPropertiesIfNeeded(object instance)
        {
            if (_configuration.EnablePropertyInjection)
            {
                var injectables = instance.GetType().GetProperties()
                                  .Where(x => (x.GetGetMethod()?.IsPublic ?? false) &&
                                         (x.GetSetMethod()?.IsPublic ?? false) &&
                                         !(x.GetGetMethod()?.IsStatic ?? false) &&
                                         x.GetValue(instance) == null);

                foreach (var injectable in injectables)
                {
                    var key = _containerHelper.GetKeyFromInjectable(injectable);

                    var injectInstance = _containerHelper.IsGenericEnumerable(injectable.PropertyType)
                        ? GetAllInstances(injectable.PropertyType.GenericTypeArguments.First(), instance, key)
                        : GetSingleInstance(injectable.PropertyType, instance, key);

                    injectable.SetValue(instance, injectInstance);
                }
            }
        }