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
Comments
Thanks for contacting us. We're moving this issue to the |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
+ public static IMvcBuilder AddControllers(this IServiceCollection services, Assembly entryAssembly)
{}
+ public static IMvcBuilder AddControllers(this IServiceCollection services, Assembly entryAssembly, Action<MvcOptions> configure)
+ {} Given that the API touches the startup code, and the plan is to update the templates we should run it by @davidfowl / @DamianEdwards |
I admit I'm not quite following the full plan here. In addition to the new overloads, are we planning to update the templates to call them? What is passed in for the |
Yup.
We want to pass in the assembly that is the root for scanning controllers / components etc. The actual value to be passed is a bit something to be figured out. We can't quite do
We hadn't discussed that, but we could consider doing so. It does mean it'll produce a lot of noise in a whole slew of apps as they are updated. |
I really don't think we should change the default/idiom here (including the template). Exposing that concept so early and for so many seems like a bad fit. For the vast majority of cases in an app, don't we just want this to be the app assembly itself, which is the entry assembly already? |
In my opinion, the way MVC detects the entry assembly is obscure and hard to find what is going on when errors similar to the reported in the issue happens, however, I think this behavior is there for so many years (i am not sure if the users complained or not before) that I agree with @DamianEdwards that is better no change the default and instead just add the new overload and we maybe we can include in the docs scenarios where they are a better option. |
Makes sense - just wanted to mention that if previous method remains, then it may be prudent to throw an exception when that method cannot locate the entry assembly due to missing prerequisite services, perhaps with the error indicating that you can call the new overload to provide the entry assembly as a param explicitly - that should catch cases like the issue linked? |
@dazinator After some discussion we decided that this API is not totally correct, and we should not add it, right now. What I will add instead, for now, is just a log message informing that no actions were detected and could be caused by a misconfiguration. Also point to this documentation Share controllers, views, Razor Pages and more with Application Parts that explains the usage of |
Background and Motivation
Currently, the default behavior in MVC to load the default
ApplicationParts
from theentryassembly
is rely on theIWebHostEnvironment
, however, as reported in the #10611, there are scenarios where the developer wants to just create a newServiceCollection
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 includeAssembly entryAssembly
parameter that will be used to load the defaultApplicationParts
from.Related:
Proposed API
Usage Examples
RazorPages
Controllers
Controllers with views
The text was updated successfully, but these errors were encountered: