【Netcore】使用 Magic生成器 ,零代码实现CRUD - HTTP REST 之接口

 

软件介绍:

Magic是一个CRUD后端生成器,内置于ASP.NET内核中。它的目的是让你“神奇地”做一些无聊的事情,通过使用自动化技术,创建80%的CRUD端点,自动包装MySQL或MS SQL Server数据库,同时你可以专注于有趣的事情。

 

一、参考文档

1、适合 ASP.NET Core 的超级-DRY开发

2、Magic 官网:https://polterguy.github.io/getting-started/

 

二、实现步骤:

Getting started

To get started with Magic you’ll need the following installed.

  1. MySQL or Microsoft SQL Server.

  2. Visual Studio Code, or Visual Studio if you’re on Windows

  3. NodeJS - To serve the frontend/dashboard

  4. Angular, which is installed using npm install -g @angular/cli after installing NodeJS

  5. DotNet CLI - Unless you’re using Visual Studio on Windows

 

List of what to do

  1. Open Visual Studio Code in your magic folder

  2. Edit your appsettings.json file, and modify your MySQL and/or MSSQL connection strings

  3. Open one terminal window and go to magic.backend

  4. Run dotnet run in the magic.backend terminal

  5. Open another terminal window and go to frontend

  6. Run npm install in this terminal

  7. When npm install from above is done, run ng serve in the frontend terminal

  8. Open your browser and point it to http://localhost:4200

Creating your first CRUD Web API

  1. Login with “root/root” as your username/password

  2. Click the “Crudify” menu item

  3. Choose your database and your table

  4. Click the “Crudify” button

When you have created your first CRUD endpoints, you can click the “Endpoints” menu item, and try out your newly created HTTP REST endpoints.

如果你在一家咨询公司工作,可能每年都会启动几个具有类似需求类型的新项目,其中需要解决每个新项目的共性。了解了客户端需求和一些初始实现之后,便可以使用超级 DRY 方法在几秒钟内完成整个项目。当然,通过标识常见模块(如身份验证和授权),可以进一步重用项目中的元素组合。通过在常见 Web API 项目中实现这些模块,可以将它们应用到任何新项目中,这些新项目会带来与你以前看到过的类似的问题。

为了方便记录,此操作听起来很简单,但事实上避免重复很难。它需要反复重构的意愿。完成重构时,还需要进一步进行重构。但好处是不容忽视的。DRY 原则可以让你近乎魔术般地创建代码,只需挥动基架魔杖,并借用现有部件组合模块。

最后,这里阐述的原则可以帮助你利用现有最佳做法创建自己的 Web API,同时避免重复。这种方法可以带来很多好处,希望它可以帮助你领会到 DRY 的美妙之处。

 

 

 

尽管出于学术原因,Magic的大部分源代码都是公开的,但它并不是开源的或免费的软件,我们会对您要运行Magic的每个服务器/主机名/DNS记录收取费用。不过,在本地开发机器上评估和使用Magic是免费的。如果您想使用Magic创建免费的开源软件,我们还可以给您一个免费的许可证密钥。请在此处或随附的许可证文件中阅读更多信息。

 

 

posted @ 2019-11-22 14:10  xixi_pan  阅读(585)  评论(0编辑  收藏  举报