Example #1
0
        public TBase Inject(TBase model, Inject inject, Type iface, TBase single)
        {
            var val = GetSingle(inject.ValueType);

            if (val == null)
            {
                val = NewInstance(inject.ValueType, inject.Args);
                switch (val)
                {
                case null when _resolved:
                    Error($"Cannot resolve interface {inject.ValueType}");
                    return(null);

                case null:
                    var pi = new PendingInjection(model, inject, model.GetType(), iface, single);
                    //Verbose(30, $"Adding {pi}");
                    _pendingInjections.Add(pi);
                    break;
                }
            }

            if (inject.PropertyInfo != null)
            {
                inject.PropertyInfo.SetValue(model, val);
            }
            else
            {
                inject.FieldInfo.SetValue(model, val);
            }

            return(model);
        }
Example #2
0
        public IBase Inject(IBase model, Inject inject, Type iface, IBase single)
        {
            var val = GetSingle(inject.ValueType);

            if (val == null)
            {
                val = NewModel(inject.ValueType, inject.Args);
                if (val == null)
                {
                    if (_resolved)
                    {
                        Error($"Cannot resolve interface {inject.ValueType}");
                        return(null);
                    }
                    var pi = new PendingInjection(model, inject, model.GetType(), iface, single);
                    Verbose(30, $"Adding {pi}");
                    _pendingInjections.Add(pi);
                }
            }

            if (inject.PropertyInfo != null)
            {
                inject.PropertyInfo.SetValue(model, val);
            }
            else
            {
                inject.FieldInfo.SetValue(model, val);
            }

            return(model);
        }