-
-
Notifications
You must be signed in to change notification settings - Fork 158
Feature Request: Use C# Source Generators to reduce boilerplate controllers #732
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
Comments
This sounds interesting. I'm wondering how you would know which controllers to generate, based on the syntax trees that represent the project source code. In the past, all resources had to be exposed as DbSet properties on DbContext, but we've recently switched to using EF Core's DbContext.Model instead, which is populated at application runtime. |
So my thinking was to determine the set of resources based on classes marked with the resource attribute. Then only emit controllers for those if there is not already a controller defined for that resource. |
I think that could work. |
Does this need to be actual real code generated - could the framework
CreateInstance of the type if it senses there isn't one? Kind of like what
ember does.
…On Mon, 18 May 2020 at 21:01, Bart Koelman ***@***.***> wrote:
I think that could work. ResourceAttribute currently requires to specify
a resource name. but we can make that optional.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#732 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABLPDFR7WRC55YR2KABXQDRSGHXXANCNFSM4MY3AUHA>
.
|
Probably that is possible too, according to https://stackoverflow.com/questions/848904/in-asp-net-mvc-is-it-possible-to-make-a-generic-controller. |
It should be fairly easily doable. |
@wayne-o @KirovAir just to be clear, this is proposing using the new Source Generators feature in the C# compiler. Source Generators are a hook into the compiler pipeline that allows you to generate the code during the compile without having to write it out to disk. They're a much more powerful form of code generation in that they have access to the compilation pipeline as well as all the traditional types of code generation sources. The thought here was that I could write a source generator that inspects the code-base for classes tagged with the ResourceAttribute and if no corresponding controller class is found, emit a boilerplate controller. This would prevent having to implement complicated generic / inheritance / DI based strategies which would make the controller interfaces more complicated than they already are. |
Description
One of my current annoyances is )that I have a lot of boilerplate controllers. This could be addressed with a Source Generator which inspects a data context and emits controllers for the configured resources.
I'll implement & PR this, I'd just like feedback on what it needs to look like.
...
Environment
The text was updated successfully, but these errors were encountered: