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(); + } + } +}