The Wayback Machine - https://web.archive.org/web/20211220193626/https://github.com/dotnet/aspnetcore/issues/39126
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding EntryAssembly to AddRazorPages/AddControllers* #39126

Open
brunolins16 opened this issue Dec 20, 2021 · 0 comments · May be fixed by #39085
Open

Adding EntryAssembly to AddRazorPages/AddControllers* #39126

brunolins16 opened this issue Dec 20, 2021 · 0 comments · May be fixed by #39085

Comments

@brunolins16
Copy link
Contributor

@brunolins16 brunolins16 commented Dec 20, 2021

Background and Motivation

Currently, the default behavior in MVC to load the default ApplicationParts from the entryassembly is rely on the IWebHostEnvironment, however, as reported in the #10611, there are scenarios where the developer wants to just create a new ServiceCollection and configure as needed. This scenario is not supported today because some providers will not be loaded, eg. RazorCompiledItemProvider required in Razor Pages.

The proposal is to add a new overload to all Add* methods available to include Assembly entryAssembly parameter that will be used to load the default ApplicationParts from.

Related:

Proposed API

namespace Microsoft.Extensions.DependencyInjection
{
   public static class MvcServiceCollectionExtensions
   {
+      public static IMvcBuilder AddControllers(this IServiceCollection services, Assembly entryAssembly) 
+      {}

+      public static IMvcBuilder AddControllers(this IServiceCollection services, Assembly entryAssembly, Action<MvcOptions>? configure)
+      {}

+      public static IMvcBuilder AddControllersWithViews(this IServiceCollection services, Assembly entryAssembly) 
+      {}

+      public static IMvcBuilder AddControllersWithViews(this IServiceCollection services, Assembly entryAssembly, Action<MvcOptions>? configure)
+      {}

+      public static IMvcBuilder AddRazorPages(this IServiceCollection services, Assembly entryAssembly) 
+      {}

+      public static IMvcBuilder AddRazorPages(this IServiceCollection services, Assembly entryAssembly, Action<RazorPagesOptions>? configure)
+      {}

   }
}
namespace Microsoft.Extensions.DependencyInjection
{
   public static class MvcCoreServiceCollectionExtensions
   {
+      public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services, Assembly entryAssembly)
+      {}
   }
}

Usage Examples

RazorPages

services.AddRazorPages(typeof(Startup).Assembly);

Controllers

services.AddControllers(typeof(Startup).Assembly);

Controllers with views

services.AddControllersWithViews(typeof(Startup).Assembly);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant