Exemplo n.º 1
0
 public EnumerableImpl(object key, Type type, Type resultType, IBuildContext firstBuildCtx, ICRegILGen firstReg)
 {
     _key = key;
     _type = type;
     _resultType = resultType;
     _list.Add(new KeyValuePair<IBuildContext, ICRegILGen>(firstBuildCtx, firstReg));
 }
Exemplo n.º 2
0
 public DelegateImpl(object key, Type type, ICRegILGen nestedRegistration)
 {
     _key = key;
     _type = type;
     _nestedRegistration = nestedRegistration;
     _myNeed = new Need {Kind = NeedKind.Constant, ClrType = _type};
 }
Exemplo n.º 3
0
 public GenerationContext(ContainerImpl container, ICRegILGen registration, IBuildContext buildContext, ParameterInfo[] parameterInfos)
 {
     _container      = container;
     _registration   = registration;
     _buildContext   = buildContext;
     _parameterInfos = parameterInfos;
 }
Exemplo n.º 4
0
 public LazyImpl(Type type, ICRegILGen nestedRegistration)
 {
     _type = type;
     _nestedRegistration = nestedRegistration;
     _myNeed             = new Need {
         Kind = NeedKind.Constant, ClrType = _type
     };
 }
Exemplo n.º 5
0
 public DelegateImpl(object?key, Type type, ICRegILGen nestedRegistration)
 {
     _key  = key;
     _type = type;
     _nestedRegistration = nestedRegistration;
     _myNeed             = new Need {
         Kind = NeedKind.Constant, ClrType = _type
     };
 }
Exemplo n.º 6
0
 internal Func<object> BuildFromRegistration(ICRegILGen registration, IBuildContext buildContext)
 {
     if (registration is ICRegFuncOptimized regOpt)
     {
         var result = (Func<object>)regOpt.BuildFuncOfT(this, typeof(Func<object>));
         if (result != null)
         {
             return result;
         }
     }
     var context = new GenerationContext(this, registration, buildContext);
     return (Func<object>)context.GenerateFunc(typeof(Func<object>));
 }
Exemplo n.º 7
0
        internal void GatherNeeds(ICRegILGen regILGen, HashSet <Tuple <IBuildContext, ICRegILGen> > processed)
        {
            var processingContext = new Tuple <IBuildContext, ICRegILGen>(_buildContext, regILGen);

            if (processed.Contains(processingContext))
            {
                return;
            }
            processed.Add(processingContext);
            foreach (var need in regILGen.GetNeeds(this))
            {
                if (need.Kind == NeedKind.CReg)
                {
                    GatherNeeds((ICRegILGen)need.Key, processed);
                    continue;
                }
                var k = new Tuple <IBuildContext, INeed>(_buildContext, need);
                if (_resolvers.ContainsKey(k))
                {
                    continue;
                }
                if (need == Need.ContainerNeed)
                {
                    _resolvers.Add(k, AddConstant(_container, need.ClrType));
                    continue;
                }
                if (need.Kind == NeedKind.Constant)
                {
                    _resolvers.Add(k, AddConstant(need.Key, need.ClrType));
                    continue;
                }
                if (need.Kind == NeedKind.ConstructorParameter)
                {
                    var reg = ResolveNeedBy(need.ClrType, need.Key);
                    if (reg == null && !need.ForcedKey)
                    {
                        reg = ResolveNeedBy(need.ClrType, null);
                    }
                    if (reg == null && need.Optional)
                    {
                        reg = new OptionalImpl(need.OptionalValue, need.ClrType);
                    }
                    if (reg == null)
                    {
                        throw new ArgumentException($"Cannot resolve {need.ClrType.ToSimpleName()} with key {need.Key}");
                    }
                    _resolvers.Add(new Tuple <IBuildContext, INeed>(_buildContext, need), reg);
                    GatherNeeds(reg, processed);
                }
            }
        }
Exemplo n.º 8
0
 internal Func<object> BuildFromRegistration(ICRegILGen registration, IBuildContext buildContext)
 {
     var regOpt = registration as ICRegFuncOptimized;
     if (regOpt != null)
     {
         var result = (Func<object>)regOpt.BuildFuncOfT(this, typeof(Func<object>));
         if (result != null)
         {
             return result;
         }
     }
     var context = new GenerationContext(this, registration, buildContext);
     return (Func<object>)context.GenerateFunc(typeof(Func<object>));
 }
Exemplo n.º 9
0
 public EnumerableImpl(object key, Type type, Type resultType, IBuildContext firstBuildCtx, ICRegILGen firstReg)
 {
     _key        = key;
     _type       = type;
     _resultType = resultType;
     _list.Add(new KeyValuePair <IBuildContext, ICRegILGen>(firstBuildCtx, firstReg));
 }
Exemplo n.º 10
0
 public SingletonImpl(Type implementationType, ICRegILGen wrapping, int singletonIndex)
 {
     _implementationType = implementationType;
     _wrapping           = wrapping;
     _singletonIndex     = singletonIndex;
 }
Exemplo n.º 11
0
 public SingletonImpl(Type implementationType, ICRegILGen wrapping, int singletonIndex)
 {
     _implementationType = implementationType;
     _wrapping = wrapping;
     _singletonIndex = singletonIndex;
 }