我想在我的存储库模式项目中生成样板代码

我想在我的存储库模式项目中生成样板代码

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

问题描述

正如标题所暗示的,我正在创建 .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.

现在,它适用于一切,包括代码优先、播种机、swagger UI、TDD 等.但是有很多地方当我想在数据库中添加新表时必须添加/修改类(请参阅 SimpleCRUD.Model > Entities)

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.

到目前为止我做了什么?

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

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

我想要达到的目标是什么?

无论如何我可以在我当前的项目中添加某种代码并在每次构建后进行检查?可行吗?还有其他建议可以让它完美运行吗?

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?

参考

我已经在其他几个框架中检查过这个工作,比如 serenity、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

我让它通过 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.

干杯

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

08-05 19:38