Пример #1
0
        /// <summary>
        /// Adds all loaded assemblies to the registered assembly list
        /// </summary>
        /// <param name="addDynamicAssemblies">Indicates if dynamic assemblies should be included</param>
        /// <param name="addFrameworkAssemblies">Indicates if .NET assemblies should be included</param>
        /// <param name="assembliesToExclude">List of assemblies to exclude</param>
        /// <returns>Current bootstrapper instance</returns>
        public virtual AutofacBootstrapperBase AddAllLoadedAssemblies(
            bool addDynamicAssemblies   = false,
            bool addFrameworkAssemblies = false,
            params Assembly[] assembliesToExclude)
        {
            var loadedAssemblies = CurrentAppDomain.GetAssemblies();

            if (!addDynamicAssemblies)
            {
                loadedAssemblies.RemoveAll(a => a.IsDynamic);
            }

            if (!addFrameworkAssemblies)
            {
                loadedAssemblies.RemoveAll(a => a.IsFrameworkAssembly());
            }

            if (assembliesToExclude != null && assembliesToExclude.Length != 0)
            {
                foreach (var assemblyToExclude in assembliesToExclude)
                {
                    loadedAssemblies.Remove(assemblyToExclude);
                }
            }

            _registeredAssemblies.AddUnique(loadedAssemblies);

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Add all assemblies decorated with the given attribute type
        /// </summary>
        /// <param name="attributeType">The type of the attribute on the assembly or MarketAssemblyAttribute if not provided</param>
        /// <returns>Current bootstrapper instance</returns>
        public virtual AutofacBootstrapperBase AddAllDecoratedAssemblies(
            Type attributeType = null)
        {
            if (attributeType == null)
            {
                attributeType = typeof(BootstrapperAssemblyAttribute);
            }

            var markedAssemblies = CurrentAppDomain
                                   .GetAssemblies()
                                   .Where(a => a.HasCustomAttribute(attributeType))
                                   .ToList();

            _registeredAssemblies.AddUnique(markedAssemblies);

            return(this);
        }
Пример #3
0
        /// <summary>
        /// Gets all loaded assemblies matching a set of names
        /// </summary>
        /// <param name="instance">The list of names to match</param>
        /// <returns>List of distinct loaded assemblies with names matching the passed in names</returns>
        public static IEnumerable <Assembly> GetAssembliesFromNames(this IEnumerable <string> instance)
        {
            if (instance == null)
            {
                throw new NullReferenceException();
            }

            var loadedAssemblies = CurrentAppDomain.GetAssemblies();

            if (loadedAssemblies != null)
            {
                return(instance
                       .Select(name => loadedAssemblies.FirstOrDefault(a => a.GetName().Name == name))
                       .Where(assembly => assembly != null)
                       .Distinct()
                       .ToList());
            }
            else
            {
                return(new List <Assembly>());
            }
        }