我想在我的存储库模式项目中生成样板代码 [英] I want to generate boiler plate code in my repository pattern project

查看:87
本文介绍了我想在我的存储库模式项目中生成样板代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,我正在创建.net core 2.0中的开源项目.这是它的体系结构.

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

现在,它可以很好地与所有功能配合使用,包括代码优先,播种器,宽大的UI,TDD等. 但是在很多地方,我想在数据库中添加新表时必须添加/修改类(请参见SimpleCRUD.Model>实体)

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?

我试图创建一个Windows应用程序,该应用程序将检查并为新添加的实体生成代码.

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?

参考

我已经在其他一些框架(例如宁静,asp.net样板等)中检查了此功能.

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

推荐答案

您已寻求我的帮助我同意您可能希望研究T4的其他海报.听起来您还想创建一个 MSBuild任务.

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

我在您可以在以下文件夹中找到我的代码生成器, CodeGen.SessionProxies

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

可以在以下位置找到t4示例: AppSessionPartials .tt

The t4 example can be found here: AppSessionPartials.tt

可以在此处找到MSBuild任务: GenerateSessionProxies.cs

The MSBuild task can be found here: GenerateSessionProxies.cs

我通过生成了一个nuget文件. CodeGen.SessionProxies.nuspec .您不会在nuget.com上找到它.我有一个本地的nuget存储库.查看相应的安装会有所帮助.ps1 了解如何将生成器设置为msbuild任务.

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.

免责声明:如果我决定清理该存储库,则所有GitHub链接都可能会中断.

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

欢呼

这篇关于我想在我的存储库模式项目中生成样板代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆