I want to generate boiler plate code in my repository pattern project

时光总嘲笑我的痴心妄想 提交于 2019-12-14 02:29:23

问题


As title suggests, I am creating open source project that is in .net core 2.0. here is the architecture of it.

Now, it's working fine with everything including code first, seeders, swagger UI, TDD etc. But there are many places where I have to add/modify classes when I want to add new Table in Database (see SimpleCRUD.Model > Entities)

So, I think I can reduce that boilerplate code, but I am not sure what is best way to do it.

What I did so far?

I tried to create a windows app, which will check and generate code for new added entity.

What I am trying to achieve?

Is there anyway I can add some kind of code in my current project and that will check after each build? is it feasible? any other suggestion to make it working perfectly?

Reference

I have checked this working in few other frameworks like serenity, asp.net boilerplate etc.


回答1:


T4 temples can help cut down the boiler plate...

https://dotnetthoughts.net/generate-your-database-entities-using-t4-templates/




回答2:


You've asked for my help here

I agree with other posters that you might want to look into T4. It sounds like you also want to create an MSBuild task.

I outlined the steps to do this for a different question in post here

You can find my code generators under this folder, CodeGen.SessionProxies

The t4 example can be found here: AppSessionPartials.tt

The MSBuild task can be found here: GenerateSessionProxies.cs

I had it generating a nuget file through the CodeGen.SessionProxies.nuspec. You won't find it on nuget.com; I had a local nuget repository. It would be helpful to you to look at the corresponding install.ps1 to understand how to set the generator up as a msbuild task.

Disclaimer: All of the GitHub links are subject to break if I ever decide to clean up that repo.

Cheers



来源:https://stackoverflow.com/questions/51453620/i-want-to-generate-boiler-plate-code-in-my-repository-pattern-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!