From 0d782d9d9abb828aa23bf8d1b36ca12a771c55f8 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Tue, 20 Sep 2016 15:35:42 -0700 Subject: [PATCH] Adding design time support for ViewComponent TagHelpers --- .../DesignTimeMvcServiceCollectionProvider.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Microsoft.AspNetCore.Mvc/DesignTimeMvcServiceCollectionProvider.cs diff --git a/src/Microsoft.AspNetCore.Mvc/DesignTimeMvcServiceCollectionProvider.cs b/src/Microsoft.AspNetCore.Mvc/DesignTimeMvcServiceCollectionProvider.cs new file mode 100644 index 0000000000..63d88557fa --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc/DesignTimeMvcServiceCollectionProvider.cs @@ -0,0 +1,24 @@ +// 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.Reflection; +using Microsoft.AspNetCore.Mvc.ApplicationParts; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.AspNetCore.Mvc +{ + internal class DesignTimeMvcServiceCollectionProvider + { + // This method invoked by RazorTooling using reflection. + public static void PopulateServiceCollection(IServiceCollection services, string assemblyName) + { + var assembly = Assembly.Load(new AssemblyName(assemblyName)); + + var partManager = new ApplicationPartManager(); + partManager.ApplicationParts.Add(new AssemblyPart(assembly)); + + services.AddSingleton(partManager); + services.AddMvc(); + } + } +}