Ejemplo n.º 1
0
        public static IDependency Get(DependencyCreationContext ctx)
        {
            var info = Get(ctx.Id, ctx.DependencyType, ctx.Kernel, ctx.InjectMany);

            if (ctx.IsOptional)
            {
                if (ctx.DefaultValue != DBNull.Value)
                {
                    info.IsOptional   = ctx.IsOptional;
                    info.DefaultValue = ctx.DefaultValue;
                }
            }
            return(info);
        }
Ejemplo n.º 2
0
        public static IDependency Get(DependencyCreationContext ctx)
        {
            var info = Get(ctx.Id, ctx.DependencyType, ctx.Kernel, ctx.InjectMany);

            if (ctx.IsOptional)
            {
                if (ctx.DefaultValue != DBNull.Value)
                {
                    info.IsOptional = ctx.IsOptional;
                    info.DefaultValue = ctx.DefaultValue;
                }
            }
            return info;
        }
Ejemplo n.º 3
0
        public static IDependency InspectParameter(IComponentInfo ctx, IKernel kernel, ParameterInfo p)
        {
            var settingAttr = p.GetAttribute <SettingAttribute>(false);

            if (settingAttr != null && !string.IsNullOrEmpty(settingAttr.Name))
            {
                return(DependencyManager.GetAppSettingDependency(settingAttr.Name, p.ParameterType));
            }

            var patt = p.GetAttribute <InjectAttribute>(false);
            var dependencyCreationCtx = new DependencyCreationContext
            {
                Id             = patt != null ? patt.Id : string.Empty,
                DependencyType = p.ParameterType,
                Kernel         = kernel,
                InjectMany     = p.HasAttribute <InjectManyAttribute>(false) ||
                                 (p.ParameterType.IsCollectionTypeExcludeStringAndDictionaryType() &&
                                  !TypeHelper.GetElementType(p.ParameterType).IsSystemAssemblyOfType() /*kernel.HasRegister(TypeHelper.GetElementType(p.ParameterType))*/),
                IsOptional   = p.IsOptional,
                DefaultValue = p.DefaultValue,
            };

            return(DependencyManager.Get(dependencyCreationCtx));
        }