Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Parity between Controller and Page/PageModel #6155

Merged
merged 1 commit into from
Apr 19, 2017

Conversation

ryanbrandenburg
Copy link
Contributor

Resolves part of #6071.

Copy link
Member

@rynowak rynowak left a 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)
Copy link
Member

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.

Copy link
Member

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(
Copy link
Member

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>>();
Copy link
Member

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(
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/PagePageModelAPISurface branch from f815979 to abc2705 Compare April 19, 2017 16:47
@ryanbrandenburg
Copy link
Contributor Author

🆙📅 The prep-work for removing Binding from Page and PageModel was going to be far-reaching enough that I erred on the side of not pre-loading it here.

/// <summary>
/// Gets the dynamic view bag.
/// </summary>
public dynamic ViewBag
Copy link
Member

@rynowak rynowak Apr 19, 2017

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

Copy link
Member

@rynowak rynowak left a 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 :shipit: 🔥 🏑

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/PagePageModelAPISurface branch from 135dbaf to c9bfd22 Compare April 19, 2017 22:02
@ryanbrandenburg ryanbrandenburg merged commit c9bfd22 into dev Apr 19, 2017
@ryanbrandenburg ryanbrandenburg deleted the rybrande/PagePageModelAPISurface branch April 19, 2017 22:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants