-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Parity between Controller and Page/PageModel #6155
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's talk about this more on Weds when I'm in the office. For now, add a few basic functional tests around TryUpdateModel
and TryValidateModel
/// A <see cref="Task{TResult}"/> which, when completed, asynchronously returns a | ||
/// <see cref="CompositeValueProvider"/>. | ||
/// </returns> | ||
public static async Task<CompositeValueProvider> CreateAsync(ActionContext actionContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really ever right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of resource filters is that they get to change the set of VPF's that apply to the action
return await CreateAsync(actionContext, factories); | ||
} | ||
|
||
private static async Task<CompositeValueProvider> CreateAsync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to make this public
throw new ArgumentNullException(nameof(actionContext)); | ||
} | ||
|
||
var mvcOptions = actionContext.HttpContext.RequestServices.GetRequiredService<IOptions<MvcOptions>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any time you use GetRequiredService
you have to pay @davidfowl a dollar.
If you see yourself using it, then stop and think about it. It's usually wrong.
var parameter = handler.Parameters[i]; | ||
arguments[i] = await page.Binder.BindModelAsync( | ||
arguments[i] = await binder.BindModelAsync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is all of this change just because we're removing Page.Binder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To this file, basically. The only other solution I can come up with is passing the binder into CreateExecutor
from PageActionInvokerProvider
. Considering PageActionInvokerProvider
already has a ton of private readonly's I guess that's cleaner as it contains the DI to one spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah or we can just move the binding up a level.
So the invoker calls model binding, and then calls the executor. The executor knows nothing about binding. This is the way it works for controllers. https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionInvoker.cs#L980
We should see if we can use ParameterBinder
here.
It might be beneficial at this point to separate the Binder
cleanup from the rest of this PR.
f815979
to
abc2705
Compare
🆙📅 The prep-work for removing |
/// <summary> | ||
/// Gets the dynamic view bag. | ||
/// </summary> | ||
public dynamic ViewBag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this for now. It makes us all sad including @DamianEdwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove ViewBag
and then party on 🔥 🏑
135dbaf
to
c9bfd22
Compare
Resolves part of #6071.