/// <summary>
        /// Registers the ASP.NET view component types using the supplied
        /// <paramref name="viewComponentDescriptorProvider"/>.
        /// </summary>
        /// <param name="container">The container the controllers should be registered in.</param>
        /// <param name="viewComponentDescriptorProvider">The provider that contains the list of view
        /// components to register.</param>
        public static void RegisterAspNetViewComponents(this Container container,
                                                        IViewComponentDescriptorProvider viewComponentDescriptorProvider)
        {
            Requires.IsNotNull(container, nameof(container));
            Requires.IsNotNull(viewComponentDescriptorProvider, nameof(viewComponentDescriptorProvider));

            var componentTypes = viewComponentDescriptorProvider
                                 .GetViewComponents()
                                 .Select(description => description.Type);

            RegisterViewComponentTypes(container, componentTypes);
        }
        /// <summary>
        /// Creates <see cref="TagHelperDescriptor"/> representations of <see cref="ViewComponent"/>s
        /// in an <see href="Assembly"/> represented by the given <paramref name="assemblyName"/>.
        /// </summary>
        /// <param name="assemblyName">The name of the assembly containing
        /// the <see cref="ViewComponent"/>s to translate.</param>
        /// <returns>A <see cref="IEnumerable{TagHelperDescriptor}"/>,
        /// one for each <see cref="ViewComponent"/>.</returns>
        public IEnumerable <TagHelperDescriptor> CreateDescriptors(string assemblyName)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException(nameof(assemblyName));
            }

            var viewComponentDescriptors = _descriptorProvider
                                           .GetViewComponents()
                                           .Where(viewComponent => string.Equals(assemblyName, viewComponent.TypeInfo.Assembly.GetName().Name,
                                                                                 StringComparison.Ordinal));

            var tagHelperDescriptors = viewComponentDescriptors
                                       .Where(d => !d.MethodInfo.ContainsGenericParameters)
                                       .Select(viewComponentDescriptor => CreateDescriptor(viewComponentDescriptor));

            return(tagHelperDescriptors);
        }
        /// <summary>
        /// Registers the ASP.NET view component types using the supplied 
        /// <paramref name="viewComponentDescriptorProvider"/>.
        /// </summary>
        /// <param name="container">The container the controllers should be registered in.</param>
        /// <param name="viewComponentDescriptorProvider">The provider that contains the list of view
        /// components to register.</param>
        public static void RegisterMvcViewComponents(this Container container,
            IViewComponentDescriptorProvider viewComponentDescriptorProvider)
        {
            Requires.IsNotNull(container, nameof(container));
            Requires.IsNotNull(viewComponentDescriptorProvider, nameof(viewComponentDescriptorProvider));

            var componentTypes = viewComponentDescriptorProvider
                .GetViewComponents()
                .Select(description => description.TypeInfo.AsType());

            RegisterViewComponentTypes(container, componentTypes);
        }
Exemplo n.º 4
0
        private ViewComponentDescriptorCollection GetViewComponents()
        {
            var descriptors = _descriptorProvider.GetViewComponents();

            return(new ViewComponentDescriptorCollection(descriptors.ToArray(), version: 0));
        }