public void CanActivateVC_Through_Activator() { lock (TestOrderingLock.Lock) { var services = new ServiceCollection(); var fakefs = new InMemoryFileProvider(); fakefs.AddFile("viewComponents/test.os", "Функция ОбработкаВызова() КонецФункции"); services.AddSingleton <IFileProvider>(fakefs); var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); cp.Engine = new ScriptingEngine(); cp.Engine.Environment = new RuntimeEnvironment(); cp.ScriptsProvider = serviceProvider.GetService <IFileProvider>(); var feature = new ViewComponentFeature(); var pm = new ApplicationPartManager(); pm.ApplicationParts.Add(new AssemblyPart(Assembly.GetExecutingAssembly())); pm.FeatureProviders.Add(cp); pm.PopulateFeature(feature); var descriptorProvider = new DefaultViewComponentDescriptorProvider(pm); var activator = new OscriptViewComponentActivator(); var descriptor = descriptorProvider.GetViewComponents().First(); var context = new ViewComponentContext(); context.ViewComponentDescriptor = descriptor; var result = activator.Create(context); Assert.IsType <ScriptedViewComponent>(result); } }
public IActionResult Index() { var viewModel = new FeaturesViewModel(); var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); viewModel.Controllers = controllerFeature.Controllers.ToList(); var metaDataReferenceFeature = new MetadataReferenceFeature(); _partManager.PopulateFeature(metaDataReferenceFeature); viewModel.MetadataReferences = metaDataReferenceFeature.MetadataReferences .ToList(); var tagHelperFeature = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeature); viewModel.TagHelpers = tagHelperFeature.TagHelpers.ToList(); var viewComponentFeature = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeature); viewModel.ViewComponents = viewComponentFeature.ViewComponents.ToList(); return(View(viewModel)); }
// Methods public ActionResult <FeaturesViewModel> Index() { // FeaturesViewModel var viewModel = new FeaturesViewModel(); { // ControllerFeature var controllerFeature = new ControllerFeature(); _applicationPartManager.PopulateFeature(controllerFeature); viewModel.Controllers = controllerFeature.Controllers.Select(x => x.FullName).ToList(); // TagHelperFeature var tagHelperFeature = new TagHelperFeature(); _applicationPartManager.PopulateFeature(tagHelperFeature); viewModel.TagHelpers = tagHelperFeature.TagHelpers.Select(x => x.FullName).ToList(); // ViewComponentFeature var viewComponentFeature = new ViewComponentFeature(); _applicationPartManager.PopulateFeature(viewComponentFeature); viewModel.ViewComponents = viewComponentFeature.ViewComponents.Select(x => x.FullName).ToList(); } // Return return(viewModel); }
public IActionResult Index() { var viewModel = new FeaturesViewModel(); var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); viewModel.Controllers = controllerFeature.Controllers.ToList(); var tagHelperFeature = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeature); viewModel.TagHelpers = tagHelperFeature.TagHelpers.ToList(); var viewComponentFeature = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeature); viewModel.ViewComponents = viewComponentFeature.ViewComponents.ToList(); var feature = new ViewsFeature(); _partManager.PopulateFeature(feature); viewModel.Views = feature.ViewDescriptors.Select(v => v.Type.GetTypeInfo()).ToList(); return(View(viewModel)); }
public static IList <TypeInfo> ViewComponents(this ApplicationPartManager applicationPartManager) { var feature = new ViewComponentFeature(); applicationPartManager.PopulateFeature(feature); return(feature.ViewComponents); }
public Task StartAsync(CancellationToken cancellationToken) { // Get the names of all the application parts. This is the short assembly name for AssemblyParts var applicationParts = _partManager.ApplicationParts.Select(x => x.Name); var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); var controllers = controllerFeature.Controllers.Select(x => x.Name); var tagHelperFeature = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeature); var tagHelpers = tagHelperFeature.TagHelpers.Select(x => x.Name); var viewComponentFeature = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeature); var viewComponents = viewComponentFeature.ViewComponents.Select(x => x.Name); var viewsFeature = new ViewsFeature(); _partManager.PopulateFeature(viewsFeature); var views = viewsFeature.ViewDescriptors.Select(x => x.RelativePath); //Log the application parts _logger.LogInformation("Found the following Application Parts: " + Environment.NewLine + string.Join(Environment.NewLine, applicationParts)); _logger.LogInformation("Found the following Controllers: " + Environment.NewLine + string.Join(Environment.NewLine, controllers)); _logger.LogInformation("Found the following Views: " + Environment.NewLine + string.Join(Environment.NewLine, views)); _logger.LogInformation("Found the following Tag Helpers: " + Environment.NewLine + string.Join(Environment.NewLine, tagHelpers)); _logger.LogInformation("Found the following View Components: " + Environment.NewLine + string.Join(Environment.NewLine, viewComponents)); return(Task.CompletedTask); }
/// <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 static Type[] GetViewComponentTypes(this IApplicationBuilder builder) { var manager = builder.ApplicationServices.GetRequiredService <ApplicationPartManager>(); var feature = new ViewComponentFeature(); manager.PopulateFeature(feature); return(feature.ViewComponents.Select(t => t.AsType()).ToArray()); }
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()); }
private static void RegisterViewComponentTypes(SimpleInjectorAspNetCoreBuilder builder) { var container = builder.Container; ApplicationPartManager manager = GetApplicationPartManager( builder.Services, nameof(AddViewComponentActivation)); var feature = new ViewComponentFeature(); manager.PopulateFeature(feature); var viewComponentTypes = feature.ViewComponents.Select(info => info.AsType()); foreach (Type type in viewComponentTypes.ToArray()) { container.AddRegistration(type, CreateConcreteRegistration(container, type)); } }
public void CanDiscoverVCThroughAllPipeline() { lock (TestOrderingLock.Lock) { var services = new ServiceCollection(); var fakefs = new InMemoryFileProvider(); fakefs.AddFile("viewComponents/test.os", "Функция ОбработкаВызова() КонецФункции"); services.AddSingleton <IFileProvider>(fakefs); services.TryAddSingleton(Mock.Of <IConfiguration>()); services.TryAddSingleton(Mock.Of <ILogger <ApplicationInstance> >()); services.TryAddSingleton(Mock.Of <IAuthorizationPolicyProvider>()); services.TryAddScoped <IHostingEnvironment>(x => new HostingEnvironment() { ContentRootPath = "/" }); var webAppMoq = new Mock <IApplicationRuntime>(); var engine = new ScriptingEngine() { Environment = new RuntimeEnvironment() }; webAppMoq.SetupGet(x => x.Engine).Returns(engine); webAppMoq.SetupGet(x => x.Environment).Returns(engine.Environment); services.AddSingleton(webAppMoq.Object); services.AddMvc() .ConfigureApplicationPartManager(pm => pm.FeatureProviders.Add(new ScriptedViewComponentFeatureProvider())); services.AddOneScript(); services.RemoveAll <ApplicationInstance>(); var provider = services.BuildServiceProvider(); var partmanager = provider.GetService <ApplicationPartManager>(); var finder = partmanager.FeatureProviders.OfType <ScriptedViewComponentFeatureProvider>() .First(); ((ScriptedViewComponentFeatureProvider)finder).Configure(provider); var feature = new ViewComponentFeature(); partmanager.PopulateFeature <ViewComponentFeature>(feature); Assert.Equal(1, feature.ViewComponents.Count); } }
public AspNetOptions AddViewComponents() { if (_parts != null) { var feature = new ViewComponentFeature(); _parts.PopulateFeature(feature); var viewComponentTypes = feature.ViewComponents.Select(v => v.AsType()); _registration.Sources(sources => sources.AddTypes(viewComponentTypes)); } _registration.Select((selector, publicOnly) => selector.AddClasses(x => x.AssignableTo <ViewComponent>(), publicOnly) .UsingRegistrationStrategy(RegistrationStrategy.Skip) .AsSelf()); _services.Replace(ServiceDescriptor .Singleton <IViewComponentActivator, ServiceBasedViewComponentActivator>()); return(this); }
/// <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); }
public void CanIgnoreModulesWithoutInvokator() { lock (TestOrderingLock.Lock) { var services = new ServiceCollection(); var fakefs = new InMemoryFileProvider(); fakefs.AddFile("viewComponents/test.os", "Функция ДругаяНоНеОбработкаВызова() КонецФункции"); services.AddSingleton <IFileProvider>(fakefs); var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); cp.Runtime = MakeRuntime(); cp.ScriptsProvider = serviceProvider.GetService <IFileProvider>(); var feature = new ViewComponentFeature(); cp.PopulateFeature(new ApplicationPart[0], feature); Assert.Equal(0, feature.ViewComponents.Count); } }
public void CanPopulateViewComponentFeature() { lock (TestOrderingLock.Lock) { var services = new ServiceCollection(); var fakefs = new InMemoryFileProvider(); fakefs.AddFile("viewComponents/test.os", "Функция ОбработкаВызова() КонецФункции"); services.AddSingleton <IFileProvider>(fakefs); var serviceProvider = services.BuildServiceProvider(); var cp = new ScriptedViewComponentFeatureProvider(); cp.Engine = new ScriptingEngine(); cp.Engine.Environment = new RuntimeEnvironment(); cp.ScriptsProvider = serviceProvider.GetService <IFileProvider>(); var feature = new ViewComponentFeature(); cp.PopulateFeature(new ApplicationPart[0], feature); Assert.Equal(1, feature.ViewComponents.Count); Assert.Equal("testViewComponent", feature.ViewComponents[0].Name); } }
public Task StartAsync(CancellationToken cancellationToken) { // Get the names of all the application parts. This is the short assembly name for AssemblyParts var applicationPartNames = _partManager.ApplicationParts.Select(x => x.Name).ToList(); // Create a controller feature, and populate it from the application parts var controllerFeature = new ControllerFeature(); _partManager.PopulateFeature(controllerFeature); // Get the names of all of the controllers var controllerNames = controllerFeature.Controllers.Select(x => x.Name).ToList(); // Create a view feature, and populate it from the application parts var viewComponentFeatures = new ViewComponentFeature(); _partManager.PopulateFeature(viewComponentFeatures); // Get the names of all of the view components var viewComponentNames = viewComponentFeatures.ViewComponents.Select(x => x.Name).ToList(); // Create a razor views feature, and populate it from the application parts var razorViewFeatures = new ViewsFeature(); _partManager.PopulateFeature(razorViewFeatures); // Get the names of all of the razor views var razorViewsNames = razorViewFeatures.ViewDescriptors.Select(x => x.RelativePath).ToList(); // Create a view feature, and populate it from the application parts var tagHelperFeatures = new TagHelperFeature(); _partManager.PopulateFeature(tagHelperFeatures); // Get the names of all of the views var tagHelperNames = tagHelperFeatures.TagHelpers.Select(x => x.Name).ToList(); // Log the controllers if (applicationPartNames.Any()) { _logger.LogInformation($"Found the following application parts: '{string.Join(", ", applicationPartNames)}'"); } // Log the controllers if (controllerNames.Any()) { _logger.LogInformation($"Found the following controllers: '{string.Join(", ", controllerNames)}'"); } // Log the controllers if (viewComponentNames.Any()) { _logger.LogInformation($"Found the following view components: '{string.Join(", ", viewComponentNames)}'"); } // Log the razor views if (razorViewsNames.Any()) { _logger.LogInformation($"Found the following razor views: '{string.Join(", ", razorViewsNames)}'"); } // Log the tag helpers if (tagHelperNames.Any()) { _logger.LogInformation($"Found the following tag helpers: '{string.Join(", ", tagHelperNames)}'"); } return(Task.CompletedTask); }