Example #1
0
 public Dependency(string id, Type dependencyType, IKernel kernel)
 {
     DependencyType = dependencyType;
     ComponentContext = kernel.GetComponentContextByNamedArgs(id, null);
     HasDependencied = ComponentContext != null;
     Id = id;
     HasId = true;
     ValueProvider = PopulateValueProvider();
 }
Example #2
0
 public Dependency(string id, Type dependencyType, IKernel kernel)
 {
     DependencyType   = dependencyType;
     ComponentContext = kernel.GetComponentContextByNamedArgs(id, null);
     HasDependencied  = ComponentContext != null;
     Id            = id;
     HasId         = true;
     ValueProvider = PopulateValueProvider();
 }
Example #3
0
        public Dependency(Type dependencyType, IKernel kernel)
        {
            DependencyType = dependencyType;

            Func<object> tmpValueProvider = () => ComponentContext.LifestyleManager.Get(ComponentContext);

            if (dependencyType.IsGenericType)
            {
                var genericFieldTypeName = dependencyType.GetGenericTypeDefinition().Name;

                GenericArguments = dependencyType.GetGenericArguments();
                if (genericFieldTypeName == "Lazy`1")
                {
                    ComponentContext = kernel.GetComponentContextByNamedArgs(GenericArguments[0], null);
                    ValueProvider = Lazy.GetLazyValueProvider(GenericArguments[0], tmpValueProvider, ComponentContext.Kernel, ComponentContext.Component);
                    IsLazyType = true;
                }
                else if (genericFieldTypeName == "Lazy`2")
                {
                    ComponentContext = kernel.GetComponentContextByNamedArgs(GenericArguments[0], null);

                    ValueProvider = Lazy.GetLazyCreator(
                        GenericArguments[0]
                        , GenericArguments[1]
                        , tmpValueProvider
                        , ComponentContext.Component.GetMetadataView(GenericArguments[1])
                        ,kernel
                        , ComponentContext.Component);
                    IsLazyType = true;
                }
            }
            if (ValueProvider == null)
            {
                ComponentContext = kernel.GetComponentContextByNamedArgs(dependencyType, null);
                ValueProvider = PopulateValueProvider();
            }
            HasDependencied = ComponentContext != null;
        }
Example #4
0
        public Dependency(Type dependencyType, IKernel kernel)
        {
            DependencyType = dependencyType;

            Func <object> tmpValueProvider = () => ComponentContext.LifestyleManager.Get(ComponentContext);

            if (dependencyType.IsGenericType)
            {
                var genericFieldTypeName = dependencyType.GetGenericTypeDefinition().Name;

                GenericArguments = dependencyType.GetGenericArguments();
                if (genericFieldTypeName == "Lazy`1")
                {
                    ComponentContext = kernel.GetComponentContextByNamedArgs(GenericArguments[0], null);
                    ValueProvider    = Lazy.GetLazyValueProvider(GenericArguments[0], tmpValueProvider, ComponentContext.Kernel, ComponentContext.Component);
                    IsLazyType       = true;
                }
                else if (genericFieldTypeName == "Lazy`2")
                {
                    ComponentContext = kernel.GetComponentContextByNamedArgs(GenericArguments[0], null);

                    ValueProvider = Lazy.GetLazyCreator(
                        GenericArguments[0]
                        , GenericArguments[1]
                        , tmpValueProvider
                        , ComponentContext.Component.GetMetadataView(GenericArguments[1])
                        , kernel
                        , ComponentContext.Component);
                    IsLazyType = true;
                }
            }
            if (ValueProvider == null)
            {
                ComponentContext = kernel.GetComponentContextByNamedArgs(dependencyType, null);
                ValueProvider    = PopulateValueProvider();
            }
            HasDependencied = ComponentContext != null;
        }
Example #5
0
 public override void Refresh(IComponentInfo info, IKernel kernel)
 {
     if (HasDependencied)
     {
         return;
     }
     if (HasId)
     {
         if (info.Id == Id)
         {
             //TODO:unit test
             ComponentContext = kernel.GetComponentContextByNamedArgs(Id, null);
             HasDependencied  = true;
             if (OnRefresh != null)
             {
                 OnRefresh();
             }
         }
     }
     else
     {
         var tmpDependencyType = IsLazyType ? GenericArguments[0] : DependencyType;
         foreach (var c in info.Contracts)
         {
             if (c == DependencyType)
             {
                 ComponentContext = kernel.GetComponentContextByNamedArgs(tmpDependencyType, null);
                 HasDependencied  = true;
                 if (OnRefresh != null)
                 {
                     OnRefresh();
                 }
                 break;
             }
         }
     }
 }
Example #6
0
 public override void Refresh(IComponentInfo info, IKernel kernel)
 {
     if (HasDependencied) return;
     if (HasId)
     {
         if (info.Id == Id)
         {
             //TODO:unit test
             ComponentContext = kernel.GetComponentContextByNamedArgs(Id, null);
             HasDependencied = true;
             if (OnRefresh != null)
                 OnRefresh();
         }
     }
     else
     {
         var tmpDependencyType = IsLazyType ? GenericArguments[0] : DependencyType;
         foreach (var c in info.Contracts)
             if (c == DependencyType)
             {
                 ComponentContext = kernel.GetComponentContextByNamedArgs(tmpDependencyType, null);
                 HasDependencied = true;
                 if (OnRefresh != null)
                     OnRefresh();
                 break;
             }
     }
 }