// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace Microsoft.AspNetCore.Mvc.ApplicationParts { /// /// Manages the parts and features of an MVC application. /// public class ApplicationPartManager { /// /// Gets the list of s. /// public IList FeatureProviders { get; } = new List(); /// /// Gets the list of instances. /// /// Instances in this collection are stored in precedence order. An that appears /// earlier in the list has a higher precendence. /// An may choose to use this an interface as a way to resolve conflicts when /// multiple instances resolve equivalent feature values. /// /// public IList ApplicationParts { get; } = new List(); /// /// Populates the given using the list of /// s configured on the /// . /// /// The type of the feature. /// The feature instance to populate. public void PopulateFeature(TFeature feature) { if (feature == null) { throw new ArgumentNullException(nameof(feature)); } foreach (var provider in FeatureProviders.OfType>()) { provider.PopulateFeature(ApplicationParts, feature); } } internal void PopulateDefaultParts(string entryAssemblyName) { var entryAssembly = Assembly.Load(new AssemblyName(entryAssemblyName)); var assembliesProvider = new ApplicationAssembliesProvider(); var applicationAssemblies = assembliesProvider.ResolveAssemblies(entryAssembly); foreach (var assembly in applicationAssemblies) { var partFactory = ApplicationPartFactory.GetApplicationPartFactory(assembly); foreach (var part in partFactory.GetApplicationParts(assembly)) { ApplicationParts.Add(part); } } } } }