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

Fixes #11904 TypeFeatureProvider throws if a Razor Page has no PageModel #11905

Merged
merged 2 commits into from
Jun 30, 2022

Conversation

jtkech
Copy link
Member

@jtkech jtkech commented Jun 27, 2022

Fixes #11904

We now can use the [Feature()] attribute on a razor PageModel if it is a component, meaning a non abstract public class, e.g. not an internal class when defined in a razor page itself, and we use the ITypeFeatureProvider to retrieve the feature related to a given PageModel.

The problem is that when no PageModel is defined for a razor page, e.g. only @functions handlers, the related page ModelType is then of type Object which is non abstract and public, so considered as a component.

In that case ITypeFeatureProvider.GetFeatureForDependency(pageModelType) throw an exception.

A quick solution was to change the following by also checking the Object type.

    private bool IsComponentType(Type type)
    {
        return type.IsClass && !type.IsAbstract && type.IsPublic &&
            type != typeof(Object); <= The change
    }

But I think it is better and simpler to just check if the page ModelType has a custom attribute of type FeatureAttribute, and if so just use it to retrieve the related feature.

@ns8482e if you can take a look ;)

@jtkech jtkech requested a review from ns8482e June 27, 2022 00:55
@ns8482e
Copy link
Contributor

ns8482e commented Jun 29, 2022

Nice - Can you add sample feature in OrchardCore.Demo?

@jtkech
Copy link
Member Author

jtkech commented Jun 29, 2022

@ns8482e Okay will do

Copy link
Contributor

@ns8482e ns8482e left a comment

Choose a reason for hiding this comment

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

LGTM

@jtkech
Copy link
Member Author

jtkech commented Jun 30, 2022

@ns8482e Okay, done and tried ;)

@sebastienros sebastienros merged commit e11e4e8 into main Jun 30, 2022
@sebastienros sebastienros deleted the jtkech-patch-1 branch June 30, 2022 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeFeatureProvider throws if a Razor Page has no PageModel
4 participants