/// <summary> /// Gets the candidate <see cref="TypeInfo"/> instances provided by the <see cref="ApplicationPartManager"/>. /// </summary> /// <returns>A list of <see cref="TypeInfo"/> instances.</returns> protected virtual IEnumerable <TypeInfo> GetCandidateTypes() { var feature = new ViewComponentFeature(); _partManager.PopulateFeature(feature); return(feature.ViewComponents); }
public void GetDescriptor_WithAttribute() { // Arrange var manager = new ApplicationPartManager(); manager.ApplicationParts.Add(new TestPart(typeof(AttributeViewComponent))); manager.FeatureProviders.Add(new ViewComponentFeatureProvider()); var feature = new ViewComponentFeature(); // Act manager.PopulateFeature(feature); // Assert Assert.Equal(new[] { typeof(AttributeViewComponent).GetTypeInfo() }, feature.ViewComponents.ToArray()); }
/// <summary> /// Registers discovered view components as services in the <see cref="IServiceCollection"/>. /// </summary> /// <param name="builder">The <see cref="IMvcBuilder"/>.</param> /// <returns>The <see cref="IMvcBuilder"/>.</returns> public static IMvcBuilder AddViewComponentsAsServices(this IMvcBuilder builder) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var feature = new ViewComponentFeature(); builder.PartManager.PopulateFeature(feature); foreach (var viewComponent in feature.ViewComponents.Select(vc => vc.AsType())) { builder.Services.TryAddTransient(viewComponent, viewComponent); } builder.Services.Replace(ServiceDescriptor.Singleton<IViewComponentActivator, ServiceBasedViewComponentActivator>()); return builder; }
/// <summary> /// Gets the candidate <see cref="TypeInfo"/> instances provided by the <see cref="ApplicationPartManager"/>. /// </summary> /// <returns>A list of <see cref="TypeInfo"/> instances.</returns> protected virtual IEnumerable<TypeInfo> GetCandidateTypes() { var feature = new ViewComponentFeature(); _partManager.PopulateFeature(feature); return feature.ViewComponents; }