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

Dependency Injector does not work with Razor Pages (VSIX-65) #39

Open
DrewBrasher opened this issue Jun 25, 2024 · 2 comments
Open

Dependency Injector does not work with Razor Pages (VSIX-65) #39

DrewBrasher opened this issue Jun 25, 2024 · 2 comments

Comments

@DrewBrasher
Copy link

DrewBrasher commented Jun 25, 2024

If I try to use the Dependency Injector in the .cshtml.cs file of a Razor Page, it gets the error:
"Could not inject dependency because the class was not found in his file"

image

Jira issue

@github-actions github-actions bot changed the title Dependency Injector does not work with Razor Pages Dependency Injector does not work with Razor Pages (VSIX-65) Jun 25, 2024
@DrewBrasher
Copy link
Author

I think this issue is because Razor Pages file names do not match the class names. So this method:

public string GetExpectedClassName(Document document)
{
// We should never get an exception here. This is just to ensure we access DTE on the main thread and get
// rid of the VSTHRD010 violation.
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
return Path.GetFileNameWithoutExtension(document.FullName);
}

for a file called Index.cshtml.cs would return Index.cshtml but the actual class name is IndexModel.

@DrewBrasher
Copy link
Author

I created pull request #40 to add support for this.

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

No branches or pull requests

1 participant