Closed wjensen closed 5 years ago
@wjensen I believe this may be what you're looking for: URF.Core.ApiControllers.Templates. Instructions are here.
This will scaffold API controllers that inject a unit of work interface with access to repositories. This is based on URF.Core.
Thanks for getting back to me. That's not quite what I am looking to do. I am looking to create a file for each entity type during scaffolding like:
foreach (var entityType in model.GetEntityTypes())
{
generatedCode = Generate(entityType.DisplayName());
resultingFiles.AdditionalFiles.Add(new ScaffoldedFile{ Path = "SomePath.cs", Code = generatedCode});
}
Does that make sense?
It all depends on what you are trying to accomplish. You could go about it a couple of different ways. The most simple might be to create a set of hbs templates for the extra files. Another might be implementing your own custom scaffolder. Can you describe more of the motivation of what you’d like to do?
I am looking to auto-generate repositories (boilerplate partials) for entities which are not lookups (500 or so) and for lookups, each entity will have auto-generated a constants class mapping the PK value to the lookup value.
I would recommend creating a different project for each of the file types you want to generate. Then update the Class.hbs
file to generate your repository class.
If this does not work for you, your next option would be to create your own implementation of ICSharpEntityTypeGenerator
with a WriteCode
method that generates your desired code. You would then implement IDesignTimeServices
to register your ICSharpEntityTypeGenerator
class.
If neither of these approaches is suitable, you might want to use the EF6 reverse engineering tools. One I like is EntityFramework Reverse POCO Generator.
Can re-open if you wish to continue the discussion.
I am interested if there is a suggested pattern for extending model code generation to produce additional files beyond the DbContext and entities? For example I would like to scaffold repositories. TIA!