/// <summary>
        /// Determine whether the provided object definition is an autowire candidate.
        /// <p>To be considered a candidate the object's <em>autowire-candidate</em>
        /// attribute must not have been set to 'false'. Also, if an attribute on
        /// the field or parameter to be autowired is recognized by this bean factory
        /// as a <em>qualifier</em>, the object must 'match' against the attribute as
        /// well as any attributes it may contain. The bean definition must contain
        /// the same qualifier or match by meta attributes. A "value" attribute will
        /// fallback to match against the bean name or an alias if a qualifier or
        /// attribute does not match.</p>
        /// </summary>
        public bool IsAutowireCandidate(ObjectDefinitionHolder odHolder, DependencyDescriptor descriptor)
        {
            if (!odHolder.ObjectDefinition.IsAutowireCandidate)
            {
                // if explicitly false, do not proceed with qualifier check
                return(false);
            }
            if (descriptor == null)
            {
                // no qualification necessaryodHolder
                return(true);
            }
            bool match = CheckQualifiers(odHolder, descriptor.Attributes);

            if (match)
            {
                MethodParameter methodParam = descriptor.MethodParameter;
                if (methodParam != null)
                {
                    var method = methodParam.MethodInfo;
                    if (method == null || method.ReturnType == typeof(void))
                    {
                        match = CheckQualifiers(odHolder, methodParam.MethodAttributes);
                    }
                }
            }
            return(match);
        }
Beispiel #2
0
        private DependencyDescriptor FindPipe(Assembly assembly, Type handlerType)
        {
            if (_pipesCache.ContainsKey(handlerType))
            {
                return(_pipesCache[handlerType]);
            }

            Type interfaceType = null;

            var implType = assembly.GetTypes().FirstOrDefault(type =>
            {
                if (type.IsAbstract)
                {
                    return(false);
                }

                var typeInterfaces = type.GetInterfaces();

                interfaceType = typeInterfaces.FirstOrDefault(@interface =>
                {
                    var ht = @interface.GenericTypeArguments.FirstOrDefault();

                    return(ht != null &&
                           ht == handlerType &&
                           @interface.GenericTypeArguments.Skip(1).FirstOrDefault() == typeof(TRequest));
                });

                return(interfaceType != null);
            });
            var dependencyDescriptor = new DependencyDescriptor(interfaceType, implType);

            _pipesCache[handlerType] = dependencyDescriptor;

            return(dependencyDescriptor);
        }
        public void LoadDescriptorsShouldWorkAcrossInstances()
        {
            var container          = BuildContainer();
            var clock              = (StubClock)container.Resolve <IClock>();
            var appDataFolder      = (StubAppDataFolder)container.Resolve <IAppDataFolder>();
            var dependenciesFolder = container.Resolve <IDependenciesFolder>();

            var d1 = new DependencyDescriptor {
                Name        = "name1",
                LoaderName  = "test1",
                VirtualPath = "~/bin1"
            };

            var d2 = new DependencyDescriptor {
                Name        = "name2",
                LoaderName  = "test2",
                VirtualPath = "~/bin2"
            };

            dependenciesFolder.StoreDescriptors(new[] { d1, d2 });

            // Create a new instance over the same appDataFolder
            var dependenciesFolder2 = container.Resolve <IDependenciesFolder>();

            Assert.NotSame(dependenciesFolder2, dependenciesFolder);

            // Ensure descriptors were persisted properly
            var result = dependenciesFolder2.LoadDescriptors();

            Assert.Equal(result.Count(), 2);
            Assert.Contains(result.Select(p => p.Name), t => t == "name1");
            Assert.Contains(result.Select(p => p.Name), t => t == "name2");
        }
        public void StoreDescriptorsShouldStoreIfChanges()
        {
            var container          = BuildContainer();
            var clock              = (StubClock)container.Resolve <IClock>();
            var appDataFolder      = (StubAppDataFolder)container.Resolve <IAppDataFolder>();
            var dependenciesFolder = container.Resolve <IDependenciesFolder>();

            var d1 = new DependencyDescriptor {
                Name        = "name1",
                LoaderName  = "test1",
                VirtualPath = "~/bin1"
            };

            var d2 = new DependencyDescriptor {
                Name        = "name2",
                LoaderName  = "test2",
                VirtualPath = "~/bin2"
            };

            dependenciesFolder.StoreDescriptors(new[] { d1, d2 });
            var dateTime1 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.json"));

            clock.Advance(TimeSpan.FromMinutes(1));

            d1.LoaderName = "bar";

            dependenciesFolder.StoreDescriptors(new[] { d2, d1 });
            var dateTime2 = appDataFolder.GetLastWriteTimeUtc(Path.Combine("Dependencies", "Dependencies.json"));

            Assert.Equal(dateTime1 + TimeSpan.FromMinutes(1), dateTime2);
        }
        /// <summary>
        /// Determines whether the specified object qualifies as an autowire candidate,
        /// to be injected into other beans which declare a dependency of matching type.
        /// This method checks ancestor factories as well.
        /// </summary>
        /// <param name="objectName">Name of the object to check.</param>
        /// <param name="descriptor">The descriptor of the dependency to resolve.</param>
        /// <returns>
        ///     <c>true</c> if the object should be considered as an autowire candidate; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="NoSuchObjectDefinitionException">if there is no object with the given name.</exception>
        public bool IsAutowireCandidate(string objectName, DependencyDescriptor descriptor)
        {
            //Consider FactoryObjects as autowiring candidates.
            bool isFactoryObject = (descriptor != null && descriptor.DependencyType != null &&
                                    typeof(IFactoryObject).IsAssignableFrom(descriptor.DependencyType));

            if (isFactoryObject)
            {
                objectName = ObjectFactoryUtils.TransformedObjectName(objectName);
            }

            if (!ContainsObjectDefinition(objectName))
            {
                if (ContainsSingleton(objectName))
                {
                    return(true);
                }
                else if (ParentObjectFactory is IConfigurableListableObjectFactory)
                {
                    // No object definition found in this factory -> delegate to parent
                    return
                        (((IConfigurableListableObjectFactory)ParentObjectFactory).IsAutowireCandidate(objectName, descriptor));
                }
            }
            return(IsAutowireCandidate(objectName, GetMergedObjectDefinition(objectName, true), descriptor));
        }
        /// <summary>
        /// Resolve the specified dependency against the objects defined in this factory.
        /// </summary>
        /// <param name="descriptor">The descriptor for the dependency.</param>
        /// <param name="objectName">Name of the object which declares the present dependency.</param>
        /// <param name="autowiredObjectNames">A list that all names of autowired object (used for
        /// resolving the present dependency) are supposed to be added to.</param>
        /// <returns>
        /// the resolved object, or <code>null</code> if none found
        /// </returns>
        /// <exception cref="ObjectsException">if dependency resolution failed</exception>
        public override object ResolveDependency(DependencyDescriptor descriptor, string objectName,
                                                 IList autowiredObjectNames)
        {
            Type type = descriptor.DependencyType;

            if (type.IsArray)
            {
                Type        elementType     = type.GetElementType();
                IDictionary matchingObjects = FindAutowireCandidates(objectName, elementType, descriptor);
                if (matchingObjects.Count == 0)
                {
                    if (descriptor.Required)
                    {
                        RaiseNoSuchObjectDefinitionException(elementType, "array of " + elementType.FullName, descriptor);
                    }
                    return(null);
                }
                if (autowiredObjectNames != null)
                {
                    foreach (DictionaryEntry matchingObject in matchingObjects)
                    {
                        autowiredObjectNames.Add(matchingObject.Key);
                    }
                }
                return(TypeConversionUtils.ConvertValueIfNecessary(type, matchingObjects.Values, null));
            }
            else if (typeof(ICollection).IsAssignableFrom(type) && type.IsInterface)
            {
                //TODO - handle generic types.
                return(null);
            }
            else
            {
                IDictionary matchingObjects = FindAutowireCandidates(objectName, type, descriptor);
                if (matchingObjects.Count == 0)
                {
                    if (descriptor.Required)
                    {
                        string methodType = (descriptor.MethodParameter.ConstructorInfo != null) ? "constructor" : "method";
                        throw new NoSuchObjectDefinitionException(type,
                                                                  "Unsatisfied dependency of type [" + type + "]: expected at least 1 matching object to wire the ["
                                                                  + descriptor.MethodParameter.ParameterName() + "] parameter on the " + methodType + " of object [" + objectName + "]");
                    }
                    return(null);
                }
                if (matchingObjects.Count > 1)
                {
                    throw new NoSuchObjectDefinitionException(type,
                                                              "expected single matching object but found " + matchingObjects.Count + ": " + matchingObjects);
                }
                DictionaryEntry entry = (DictionaryEntry)ObjectUtils.EnumerateFirstElement(matchingObjects);
                if (autowiredObjectNames != null)
                {
                    autowiredObjectNames.Add(entry.Key);
                }
                return(entry.Value);
            }
        }
            public override void Inject(Object instance, String objectName, IPropertyValues pvs)
            {
                var field = (FieldInfo)_member;

                try
                {
                    Object value;
                    if (_cached)
                    {
                        value = ResolvedCachedArgument(objectName, _cachedFieldValue);
                    }
                    else
                    {
                        var   descriptor           = new DependencyDescriptor(field, _required);
                        IList autowiredObjectNames = new ArrayList();
                        value = _objectFactory.ResolveDependency(descriptor, objectName, autowiredObjectNames);
                        lock (this)
                        {
                            if (!_cached)
                            {
                                if (value != null || _required)
                                {
                                    _cachedFieldValue = descriptor;
                                    RegisterDependentObjects(objectName, autowiredObjectNames);
                                    if (autowiredObjectNames.Count == 1)
                                    {
                                        var autowiredBeanName = autowiredObjectNames[0] as string;
                                        if (_objectFactory.ContainsObject(autowiredBeanName))
                                        {
                                            if (_objectFactory.IsTypeMatch(autowiredBeanName, field.GetType()))
                                            {
                                                _cachedFieldValue = new RuntimeObjectReference(autowiredBeanName);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _cachedFieldValue = null;
                                }
                                _cached = true;
                            }
                        }
                    }
                    if (value != null)
                    {
                        field.SetValue(instance, value);
                    }
                }
                catch (Exception ex)
                {
                    throw new ObjectCreationException("Could not autowire field: " + field, ex);
                }
            }
        /// <summary>
        /// Determine whether the given dependency carries a value attribute.
        /// </summary>
        public Object GetSuggestedValue(DependencyDescriptor descriptor)
        {
            Object value = FindValue(descriptor.Attributes);

            if (value == null)
            {
                MethodParameter methodParam = descriptor.MethodParameter;
                if (methodParam != null)
                {
                    value = FindValue(methodParam.MethodAttributes);
                }
            }
            return(value);
        }
 /// <summary>
 /// Gets the <paramref name="dependency"/>'s contract if it is injected as <see cref="Func{TResult}"/>.
 /// </summary>
 /// <param name="dependency"> The extended <see cref="DependencyDescriptor"/>. </param>
 /// <returns> The contract of the injected dependency (i.e. the factories return type). </returns>
 public static string Contract(this DependencyDescriptor dependency)
 {
     if (dependency.Contract.FullName.StartsWith("System.Func<", StringComparison.Ordinal))
     {
         var start  = "System.Func<".Length;
         var length = dependency.Contract.FullName.Length - start - 1;
         return(dependency.Contract.FullName.Substring(start, length));
     }
     else if (dependency.Contract.FullName.StartsWith("Func<", StringComparison.Ordinal))
     {
         var start  = "Func<".Length;
         var length = dependency.Contract.FullName.Length - start - 1;
         return(dependency.Contract.FullName.Substring(start, length));
     }
     return(dependency.Contract.FullName);
 }
        public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency)
        {
            if (_assemblyProbingFolder.AssemblyExists(dependency.Name))
            {
                ctx.DeleteActions.Add(
                    () => {
                    Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from probing directory", dependency.Name);
                    _assemblyProbingFolder.DeleteAssembly(dependency.Name);
                });

                // We need to restart the appDomain if the assembly is loaded
                if (_hostEnvironment.IsAssemblyLoaded(dependency.Name))
                {
                    Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
                    ctx.RestartAppDomain = true;
                }
            }
        }
        public void StoreDescriptorsShouldWork()
        {
            var dependenciesFolder = BuildContainer().Resolve <IDependenciesFolder>();

            var d = new DependencyDescriptor {
                Name        = "name",
                LoaderName  = "test",
                VirtualPath = "~/bin"
            };

            dependenciesFolder.StoreDescriptors(new[] { d });
            var e = dependenciesFolder.LoadDescriptors();

            Assert.That(e, Has.Count.EqualTo(1));
            Assert.That(e.First().Name, Is.EqualTo("name"));
            Assert.That(e.First().LoaderName, Is.EqualTo("test"));
            Assert.That(e.First().VirtualPath, Is.EqualTo("~/bin"));
        }
        /// <summary>
        /// Get the correct "CreateOrGetService" / "CreateOrGetNamedService" call for the given <paramref name="dependency"/>.
        /// </summary>
        /// <param name="dependency"> The extended <see cref="DependencyDescriptor"/>. </param>
        /// <returns>
        /// The corret call for creating an instance of the given <paramref name="dependency"/>.
        /// </returns>
        public static string CreateOrGetService(this DependencyDescriptor dependency)
        {
            if (dependency.Contract.FullName.StartsWith("Func<", StringComparison.Ordinal) ||
                dependency.Contract.FullName.StartsWith("System.Func<", StringComparison.Ordinal))
            {
                if (string.IsNullOrEmpty(dependency.ServiceId))
                {
                    return($"new Func<{dependency.Contract()}>(((IServiceFactory<{dependency.Contract()}>)this).CreateOrGetService)");
                }
                return($"new Func<{dependency.Contract()}>(((INamedServiceFactory<{dependency.Contract()}>)this).CreateOrGetNamedService(\"{dependency.ServiceId}\"))");
            }

            if (string.IsNullOrEmpty(dependency.ServiceId))
            {
                return($"((IServiceFactory<{dependency.Contract.FullName}>)this).CreateOrGetService()");
            }
            return($"((INamedServiceFactory<{dependency.Contract.FullName}>)this).CreateOrGetNamedService(\"{dependency.ServiceId}\")");
        }
        public void StoreDescriptorsShouldWork()
        {
            var dependenciesFolder = BuildContainer().Resolve <IDependenciesFolder>();

            var d = new DependencyDescriptor {
                Name        = "name",
                LoaderName  = "test",
                VirtualPath = "~/bin"
            };

            dependenciesFolder.StoreDescriptors(new[] { d });
            var e = dependenciesFolder.LoadDescriptors();

            Assert.NotNull(e);
            Assert.Equal(e.Count(), 1);
            Assert.Equal(e.First().Name, "name");
            Assert.Equal(e.First().LoaderName, "test");
            Assert.Equal(e.First().VirtualPath, "~/bin");
        }
        private string GetExtensionHash(ExtensionLoadingContext context, DependencyDescriptor dependencyDescriptor)
        {
            var hash = new Hash();

            hash.AddStringInvariant(dependencyDescriptor.Name);

            foreach (var virtualpathDependency in context.ProcessedExtensions[dependencyDescriptor.Name].VirtualPathDependencies)
            {
                hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, virtualpathDependency));
            }

            foreach (var reference in dependencyDescriptor.References)
            {
                hash.AddStringInvariant(reference.Name);
                hash.AddString(reference.LoaderName);
                hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, reference.VirtualPath));
            }

            return(hash.Value);
        }
Beispiel #15
0
        /// <summary>
        /// 扩展删除。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="dependency">依赖项描述符。</param>
        public override void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
        {
            if (!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(dependency.Name)))
            {
                return;
            }

            context.DeleteActions.Add(
                () =>
            {
                Logger.Information("ExtensionRemoved: 删除在探测目录中的程序集 \"{0}\"", dependency.Name);
                _assemblyProbingFolder.DeleteAssembly(dependency.Name);
            });

            //如果程序集已经被加载,需要重新启动AppDomain
            if (!_hostEnvironment.IsAssemblyLoaded(dependency.Name))
            {
                return;
            }
            Logger.Information("ExtensionRemoved: 模块\"{0}\"被删除,它的程序集加载,迫使AppDomain重启", dependency.Name);
            context.RestartAppDomain = true;
        }
 /// <summary>
 /// 获取依赖文件的虚拟路径。
 /// </summary>
 /// <param name="dependency">依赖项描述符。</param>
 /// <returns>虚拟路径集合。</returns>
 public virtual IEnumerable <string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     return(Enumerable.Empty <string>());
 }
 /// <summary>
 /// 获取编译引用信息。
 /// </summary>
 /// <param name="dependency"></param>
 /// <returns>扩展编译引用集合。</returns>
 public virtual IEnumerable <ExtensionCompilationReference> GetCompilationReferences(DependencyDescriptor dependency)
 {
     return(Enumerable.Empty <ExtensionCompilationReference>());
 }
 /// <summary>
 /// 扩展删除。
 /// </summary>
 /// <param name="context">扩展装载上下文。</param>
 /// <param name="dependency">依赖项描述符。</param>
 public virtual void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
 {
 }
        public void CodeGenerationStarted(RazorBuildProvider provider)
        {
            var assembliesToAdd = new List <Assembly>();

            DependencyDescriptor moduleDependencyDescriptor = GetModuleDependencyDescriptor(provider.VirtualPath);

            IEnumerable <DependencyDescriptor> dependencyDescriptors = _dependenciesFolder.LoadDescriptors();
            List <DependencyDescriptor>        filteredDependencyDescriptors;

            if (moduleDependencyDescriptor != null)
            {
                // Add module
                filteredDependencyDescriptors = new List <DependencyDescriptor> {
                    moduleDependencyDescriptor
                };

                // Add module's references
                filteredDependencyDescriptors.AddRange(moduleDependencyDescriptor.References
                                                       .Select(reference => dependencyDescriptors
                                                               .FirstOrDefault(dependency => dependency.Name == reference.Name)
                                                               ?? new DependencyDescriptor
                {
                    LoaderName  = reference.LoaderName,
                    Name        = reference.Name,
                    VirtualPath = reference.VirtualPath
                }
                                                               ));
            }
            else
            {
                // Fall back for themes
                filteredDependencyDescriptors = dependencyDescriptors.ToList();
            }

            var entries = filteredDependencyDescriptors
                          .SelectMany(descriptor => _loaders
                                      .Where(loader => descriptor.LoaderName == loader.Name)
                                      .Select(loader => new
            {
                loader,
                descriptor,
                references   = loader.GetCompilationReferences(descriptor),
                dependencies = _extensionDependenciesManager.GetVirtualPathDependencies(descriptor.Name)
            }));

            // Add assemblies
            foreach (var entry in entries)
            {
                foreach (var reference in entry.references)
                {
                    if (!string.IsNullOrEmpty(reference.AssemblyName))
                    {
                        var assembly = _assemblyLoader.Load(reference.AssemblyName);
                        if (assembly != null)
                        {
                            assembliesToAdd.Add(assembly);
                        }
                    }
                    if (!string.IsNullOrEmpty(reference.BuildProviderTarget))
                    {
                        // Returned assembly may be null if the .csproj file doesn't containt any .cs file, for example
                        var assembly = _buildManager.GetCompiledAssembly(reference.BuildProviderTarget);
                        if (assembly != null)
                        {
                            assembliesToAdd.Add(assembly);
                        }
                    }
                }
            }

            foreach (var assembly in assembliesToAdd)
            {
                provider.AssemblyBuilder.AddAssemblyReference(assembly);
            }

            // Add virtual path dependencies (i.e. source files)
            //PERF: Ensure each virtual path is present only once in the list of dependencies
            var virtualDependencies = entries
                                      .SelectMany(e => e.dependencies)
                                      .Distinct(StringComparer.OrdinalIgnoreCase)
                                      .ToList();

            foreach (var virtualDependency in virtualDependencies)
            {
                provider.AddVirtualPathDependency(virtualDependency);
            }

            // Logging
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                if (assembliesToAdd.Count == 0 && provider.VirtualPathDependencies == null)
                {
                    Logger.Debug("CodeGenerationStarted(\"{0}\") - no dependencies.", provider.VirtualPath);
                }
                else
                {
                    Logger.Debug("CodeGenerationStarted(\"{0}\") - Dependencies: ", provider.VirtualPath);
                    if (provider.VirtualPathDependencies != null)
                    {
                        foreach (var virtualPath in provider.VirtualPathDependencies)
                        {
                            Logger.Debug("  VirtualPath: \"{0}\"", virtualPath);
                        }
                    }
                    foreach (var assembly in assembliesToAdd)
                    {
                        Logger.Debug("  Reference: \"{0}\"", assembly);
                    }
                }
            }
        }
 public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency)
 {
     DeleteAssembly(ctx, dependency.Name);
 }
 /// <summary>
 /// 获取编译引用信息。
 /// </summary>
 /// <param name="dependency"></param>
 /// <returns>扩展编译引用集合。</returns>
 public virtual IEnumerable<ExtensionCompilationReference> GetCompilationReferences(DependencyDescriptor dependency)
 {
     return Enumerable.Empty<ExtensionCompilationReference>();
 }
 /// <summary>
 /// 扩展删除。
 /// </summary>
 /// <param name="context">扩展装载上下文。</param>
 /// <param name="dependency">依赖项描述符。</param>
 public virtual void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
 {
 }
        /// <summary>
        /// 扩展删除。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="dependency">依赖项描述符。</param>
        public override void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
        {
            if (!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(dependency.Name)))
                return;

            context.DeleteActions.Add(
                () =>
                {
                    Logger.Information("ExtensionRemoved: 删除在探测目录中的程序集 \"{0}\"", dependency.Name);
                    _assemblyProbingFolder.DeleteAssembly(dependency.Name);
                });

            //如果程序集已经被加载,需要重新启动AppDomain
            if (!_hostEnvironment.IsAssemblyLoaded(dependency.Name))
                return;
            Logger.Information("ExtensionRemoved: 模块\"{0}\"被删除,它的程序集加载,迫使AppDomain重启", dependency.Name);
            context.RestartAppDomain = true;
        }
 public IEnumerable <string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     throw new NotImplementedException();
 }
 public override IEnumerable <ExtensionCompilationReference> GetCompilationReferences(DependencyDescriptor dependency)
 {
     yield return(new ExtensionCompilationReference {
         BuildProviderTarget = dependency.VirtualPath
     });
 }
 /// <summary>
 /// Determine whether a default value is suggested for the given dependency.
 /// </summary>
 /// <param name="descriptor">The descriptor for the target method parameter or field</param>
 /// <returns>The value suggested (typically an expression String),
 /// or <c>null</c> if none found
 /// </returns>
 public object GetSuggestedValue(DependencyDescriptor descriptor)
 {
     return(null);
 }
 public void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency)
 {
     throw new NotImplementedException();
 }
        private string GetExtensionHash(ExtensionLoadingContext context, DependencyDescriptor dependencyDescriptor)
        {
            var hash = new Hash();
            hash.AddStringInvariant(dependencyDescriptor.Name);

            foreach (var virtualpathDependency in context.ProcessedExtensions[dependencyDescriptor.Name].VirtualPathDependencies)
            {
                hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, virtualpathDependency));
            }

            foreach (var reference in dependencyDescriptor.References)
            {
                hash.AddStringInvariant(reference.Name);
                hash.AddString(reference.LoaderName);
                hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, reference.VirtualPath));
            }

            return hash.Value;
        }
 public IEnumerable <ExtensionCompilationReference> GetCompilationReferences(DependencyDescriptor dependency)
 {
     throw new NotImplementedException();
 }
 public override IEnumerable <string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     yield return(_assemblyProbingFolder.GetAssemblyVirtualPath(dependency.Name));
 }
 /// <summary>
 /// 扩展删除。
 /// </summary>
 /// <param name="context">扩展装载上下文。</param>
 /// <param name="dependency">依赖项描述符。</param>
 public override void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
 {
     DeleteAssembly(context, dependency.Name);
 }
 /// <summary>
 /// 获取依赖文件的虚拟路径。
 /// </summary>
 /// <param name="dependency">依赖项描述符。</param>
 /// <returns>虚拟路径集合。</returns>
 public override IEnumerable<string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     yield return _assemblyProbingFolder.GetAssemblyVirtualPath(new AssemblyDescriptor(dependency.Name));
 }
 /// <summary>
 /// 获取编译引用信息。
 /// </summary>
 /// <param name="dependency"></param>
 /// <returns>扩展编译引用集合。</returns>
 public override IEnumerable<ExtensionCompilationReference> GetCompilationReferences(DependencyDescriptor dependency)
 {
     yield return new ExtensionCompilationReference { AssemblyName = dependency.Name };
 }
Beispiel #34
0
 /// <summary>
 /// Determines whether the given object definition qualifies as an
 /// autowire candidate for the given dependency.
 /// </summary>
 /// <param name="odHolder">The object definition including object name and aliases.</param>
 /// <param name="descriptor">The descriptor for the target method parameter or field.</param>
 /// <returns>
 ///     <c>true</c> if the object definition qualifies as autowire candidate; otherwise, <c>false</c>.
 /// </returns>
 public bool IsAutowireCandidate(ObjectDefinitionHolder odHolder, DependencyDescriptor descriptor)
 {
     return(odHolder.ObjectDefinition.IsAutowireCandidate);
 }
 public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency)
 {
 }
 /// <summary>
 /// 获取依赖文件的虚拟路径。
 /// </summary>
 /// <param name="dependency">依赖项描述符。</param>
 /// <returns>虚拟路径集合。</returns>
 public virtual IEnumerable<string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     return Enumerable.Empty<string>();
 }
 public override IEnumerable <string> GetVirtualPathDependencies(DependencyDescriptor dependency)
 {
     // Return csproj and all .cs files
     return(GetDependencies(dependency.VirtualPath));
 }
            public override void Inject(Object target, string objectName, IPropertyValues pvs)
            {
                MethodInfo method = _member as MethodInfo;

                try
                {
                    Object[] arguments;
                    if (_cached)
                    {
                        arguments = ResolveCachedArguments(objectName);
                    }
                    else
                    {
                        Type[] paramTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();
                        arguments = new Object[paramTypes.Length];
                        var   descriptors        = new DependencyDescriptor[paramTypes.Length];
                        IList autowiredBeanNames = new ArrayList();
                        for (int i = 0; i < arguments.Length; i++)
                        {
                            MethodParameter methodParam = new MethodParameter(method, i);
                            descriptors[i] = new DependencyDescriptor(methodParam, _required);
                            arguments[i]   = _objectFactory.ResolveDependency(descriptors[i], objectName,
                                                                              autowiredBeanNames);
                            if (arguments[i] == null && !_required)
                            {
                                arguments = null;
                                break;
                            }
                        }
                        lock (this)
                        {
                            if (!_cached)
                            {
                                if (arguments != null)
                                {
                                    _cachedMethodArguments = new Object[arguments.Length];
                                    for (int i = 0; i < arguments.Length; i++)
                                    {
                                        _cachedMethodArguments[i] = descriptors[i];
                                    }
                                    RegisterDependentObjects(objectName, autowiredBeanNames);
                                    if (autowiredBeanNames.Count == paramTypes.Length)
                                    {
                                        for (int i = 0; i < paramTypes.Length; i++)
                                        {
                                            string autowiredBeanName = autowiredBeanNames[i] as string;
                                            if (_objectFactory.ContainsObject(autowiredBeanName))
                                            {
                                                if (_objectFactory.IsTypeMatch(autowiredBeanName, paramTypes[i]))
                                                {
                                                    _cachedMethodArguments[i] =
                                                        new RuntimeObjectReference(autowiredBeanName);
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _cachedMethodArguments = null;
                                }
                                _cached = true;
                            }
                        }
                    }
                    if (arguments != null)
                    {
                        method.Invoke(target, arguments);
                    }
                }
                catch (Exception ex)
                {
                    throw new ObjectCreationException("Could not autowire method: " + method, ex);
                }
            }