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

Scaffolding: Create default templates #28549

Merged
merged 1 commit into from
Aug 9, 2022
Merged

Scaffolding: Create default templates #28549

merged 1 commit into from
Aug 9, 2022

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented Jul 29, 2022

This refactors our existing scaffolding code into T4 templates that we can both precompile to use as our default code generator and also ship somehow (probably dotnet new) as a starting point for users to customize.

Note, we're still reviewing and refining the templates. But the bulk of the changes are ready to go. I'll update this PR as work progresses, but we could also just do the fine-tuning in a later PR if we're ready to merge this one.

Part of #4038, part of #14545, resolves #25546, resolves #25547, fixes #27087, part of #27588, fixes #28187

@bricelam bricelam requested a review from a team July 29, 2022 22:30
@ajcvickers
Copy link
Member

@bricelam Is this ready for review? Looks like you just pushed changes.

@bricelam
Copy link
Contributor Author

bricelam commented Aug 1, 2022

Yes, it can be reviewed. I expect a few more tweaks to the templates, but this could be merged to unblock others from working on scaffolding. They can always be fine-tuned in a later PR.

Looks like you just pushed changes.

Just fixing the failing test.

/// <param name="index">The index.</param>
/// <param name="annotationCodeGenerator">The provider's annotation code generator.</param>
/// <returns><see langword="true"/> if this index can be reperesented by a data annotation.</returns>
public static bool HasDataAnnotation(this IIndex index, IAnnotationCodeGenerator annotationCodeGenerator)
Copy link
Member

Choose a reason for hiding this comment

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

Is HasDataAnnotation the right name for "can be entirely reperesented by a data annotation?"

Copy link
Member

Choose a reason for hiding this comment

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

Also, spelling, apparently. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to change it. To the user, these usually appear in predicates like Options.UseDataAnnotations && x.HasDataAnnotation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HandledByDataAnnotations might be a good alternative.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 4, 2022

@bricelam wonder how EF Core Power Tools can take advantage of all this, as it does not attempt to load the users project in any way. 🤥

@bricelam
Copy link
Contributor Author

bricelam commented Aug 4, 2022

@ErikEJ It should be able to work just fine without loading the user's assembly. If you just set ModelCodeGenerationOptions.ProjectDir to the user's project, the TextTemplatingModelGenerator service will discover and use the CodeTemplates\EFCore\DbContext.t4 and EntityType.t4 files.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 4, 2022

@bricelam Wonderful!

@bricelam
Copy link
Contributor Author

bricelam commented Aug 4, 2022

@ErikEJ I'm also working on a dotnet new experience for acquiring the default templates in bricelam:new, but just like in the EF6 Power Tools, it could be nice to have a gesture for this in the EF Core Power Tools too.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 4, 2022

@bricelam Yes, I plan to include the default templates and Allow the user to drop them in the project just like with Handlebars templates today. And potentially offer more template sets over time for special use cases like UI modelbinding.

This refactors our existing scaffolding code into T4 templates that we can both precompile to use as our default code generator and also ship somehow (probably `dotnet new`) as a starting point for users to start customizing.

Part of dotnet#4038, part of dotnet#14545, fixes dotnet#25473, resolves dotnet#25546, resolves dotnet#25547, fixes dotnet#27087, part of dotnet#27588, fixes dotnet#28187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants