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

Introducing IPageModelActivatorProvider #5712

Closed
wants to merge 1 commit into from

Conversation

pranavkm
Copy link
Contributor

Fixes #5480

namespace Microsoft.AspNetCore.Mvc.RazorPages
{
/// <summary>
/// Provides methods for creation and disposal of Razor page models.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The P should be capitalized because it's a proper name #JustEilonThings

using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a .Infrastructure namespace already parked it would be good to put this there and document it for extensibility. It was common in the past to subclass our factories.

}

var factory = ActivatorUtilities.CreateFactory(modelTypeInfo, Type.EmptyTypes);
return (context) => factory(context.HttpContext.RequestServices, EmptyArray<object>.Instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be dope to put this part into a virtual method, then there's less boilerplate if you want to use something other than ActivatorUtilities.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, my brain is crazy. Ignore this comment as soon as possible

/// the model instance. The property must have a public set method.
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class PageContextAttribute : Attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go in .Infrastructure? Do whatever we did with ActionContextAttribute.

/// <summary>
/// <see cref="IPageActivatorProvider"/> that uses type activation to create Pages.
/// </summary>
public class DefaultPageModelActivatorProvider : IPageModelActivatorProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll also need the equivalent plumbing for the DI versions of these. Please open an issue for that or do it right away 👍

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.

:shipit: looks good

@pranavkm pranavkm closed this Feb 2, 2017
@dougbu dougbu deleted the prkrishn/model-activation branch July 15, 2018 03:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants