csharpfritz / InstantAPIs

A library that generates Minimal API endpoints for an Entity Framework context.
MIT License
447 stars 57 forks source link

Creating a source generator #19

Closed JasonBock closed 2 years ago

JasonBock commented 2 years ago

I've added two projects:

The approach I look to generate the extension method can be changed. For the MVP, I decided to just look for DbContext derived classes. Maybe we change that to have an additional file that specifies which contexts should be mapped. Or, we create an attribute that the developer has to put on the context, though I think that's probably not the right place for the attribute. Meaning, you may be defining the context in a library, and you reference that library from the web project. Rather, we'd have an assembly-level attribute that would say something like [assembly: InstantAPIs(typeof(MyContext))] (and with the potential of generic attributes in C# in the future, we could make that attribute a generic).

I have comments in Program.cs that describes how you can switch to the source generator approach. Let me know what you think!

csharpfritz commented 2 years ago

Thank you so much! Merged.. and I'll set up some directions on the README as well as a publish to NuGet

JasonBock commented 2 years ago

Awesome!

In the future, if there are any features being added, we just need to make sure they're done with both the Reflection and SG approaches. I'll try to stay on top of the SG side.