[Open source] FreeSql.AdminLTE feature upgrades

Foreword

FreeSql released so far has been nine months, function gradually improved, gradually form their own ecosystem, as early as a few months ago wrote an article "ORM development environment of the weapon: MVC middleware FreeSql.AdminLTE" , you can read Learn the ins and outs on article content, then come back here to watch.

I personally like small teams "go it alone", sometimes even in large companies, but also doing a small project team of 3-5 individuals, I believe many people have had similar experiences.

As it can be seen from the article, earlier FreeSql.AdminLTE just a vase, very limited application scenarios, test data management purposes only in the development environment, a few months after that I basically did not actually use it. . . Is not it embarrassing? ?

The feature upgrade situation has changed, and the first to read this article.

  • I like to have management functions, hoping for secondary development on the default function generated;

  • I like to keep it simple, easy to use, do not be too difficult to develop secondary.

When it comes to open source repository or affixed to it: https://github.com/2881099/FreeSql.AdminLTE , the main project FreeSql currently has more than 900 stars, while welcome to praise, thank you!

Background of the project

For producing generic background management system, in addition to simple single-table crud operation, I also like to have a foreign key operations, such as:

1, Song, Tag-many scenario to add / Tag can be saved along with updates Song;

2, a list of pages, we hope the foreign key, appear in many-filtration filter criteria;

3, list page, hoping to enumerate appear in the filter filter criteria;

So on and so complicated operation, the reason that complicated, is not difficult because these techniques work, is a serious duplication of effort.

In staffing harsh environments, maximize productivity by selecting tools, so we have more time to goof off at work. . .

Since ORM entity has been configured using the convenient conditions existing generation back office functions, it is really a great joy! !

Function library division

project version
FreeSqlAdminLTE netstandard2.0、net45
FreeSql.AdminLTE.Tools netcoreapp2.1
FreeSqlAdminLTEPreview netstandard2.0

Three packages produced AdminLTE function almost the same, are cumbersome to generate the default background management functions according to the entity classes, navigation relationship.

Common input conditions:

  • Annotated entity classes (open the project XML documents);
  • Navigation attributes entity class configuration (conventional cumbersome generate background management functions).

FreeSqlAdminLTEPreview

.NETCore MVC middleware, AdminLTE dynamically generated based on the specified front-end frame deletions FreeSql entity changed Preview to check management].

Usage scenarios: development environment, production test data.

dotnet add package FreeSql.AdminLTE.Preview

public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<IFreeSql>(fsql);
}

public void Configure(IApplicationBuilder app)
{
    app.UseFreeAdminLtePreview("/testadmin/",
        typeof(TestDemo01.Entitys.Song),
        typeof(TestDemo01.Entitys.Tag));
}

image

image

FreeSqlAdminLTE

FreeSql entity classes based on configuration, navigation relationship configuration, quickly generate the code based on the additions and deletions to change search MVC + Razor + AdminLTE back office systems to support the secondary development of [].

Usage scenarios: asp.net/asp.netcore back office systems generate fast, secondary development [Custom].

dotnet add package FreeSql.AdminLTE

using (var gen = new FreeSql.AdminLTE.Generator(new GeneratorOptions()))
{
    gen.Build("d:/test/", new[] { typeof(TestDemo01.Entitys.Song) }, false);
}

remind! remind! remind!

Controller after generating, dependent on the code FreeSql.DbContext Razor libraries, manually add

Heavy functions: FreeSql.AdminLTE.Tools

What tools more efficient?

Command Line. . . Command Line. . . Command Line. . . It must be! ! !

Brief Global Tools, it is a characteristic of .NET Core 2.1 in a first arise. Global Tools provides a way for developers to write .NET Core applications can be packaged into NuGet package delivery. If .NET Core running on the target platform, then a proper packaged Global Tool can run up there. JavaScript developers might find interesting thing is that this tool is directly borrowed NPM Global Tools.

FreeSql.AdminLTE.Tools 是对 FreeSql.AdminLTE 功能的工具命令化封装,命令行快速生成代码。

使用场景:asp.netcore 后台管理系统快速生成,二次开发。

dotnet tool install -g FreeSql.AdminLTE.Tools


进入后台项目(可以是空项目、或已存在的项目),执行以下命令

FreeSql.AdminLTE.Tools -Find MyTest.Model..+

命令行参数 说明
-Find * 匹配实体类FullName的正则表达式
-ControllerNameSpace 控制器命名空间(默认:FreeSql.AdminLTE)
-ControllerRouteBase 控制器请求路径前辍(默认:/AdminLTE/)
-ControllerBase 控制器基类(默认:Controller)
-First 是否生成 ApiResult.cs、index.html、htm 静态资源(首次生成)
-Output 输出路径(默认:当前目录)

打开 command 命令行,执行效果如下:

>dotnet tool install -g FreeSql.AdminLTE.Tools
可使用以下命令调用工具: FreeSql.AdminLTE.Tools
已成功安装工具“freesql.adminlte.tools”(版本“0.9.4”)。

>FreeSql.AdminLTE.Tools
        ____                   ____         __
       / __/  ____ ___  ___   / __/ ___ _  / /
      / _/   / __// -_)/ -_) _\ \  / _ `/ / /
     /_/    /_/   \__/ \__/ /___/  \_, / /_/
                                    /_/


  # Github # https://github.com/2881099/FreeSql


    基于 .NETCore 2.1 环境,在控制台当前目录的项目下,根据实体类生成 AdminLTE 后台管理功能的相关文件。

  # 生成条件 #

    1、实体类的注释(请开启项目XML文档);
    2、实体类的导航属性配置(可生成繁琐的常用后台管理功能)。

  # 快速开始 #

    > FreeSql.AdminLTE.Tools -Find MyTest\.Model\..+

        -Find                  * 匹配实体类FullName的正则表达式

        -ControllerNameSpace   控制器命名空间(默认:FreeSql.AdminLTE)
        -ControllerRouteBase   控制器请求路径前辍(默认:/AdminLTE/)
        -ControllerBase        控制器基类(默认:Controller)

        -First             是否生成 ApiResult.cs、index.html、htm 静态资源(首次生成)
        -Output                输出路径(默认:当前目录)

  # 生成到其他目录 #

    > FreeSql.AdminLTE.Tools -Find MyTest\.Model\..+ -Output d:/test

演示

1、在桌面创建目录:MyProject

2、打开 cmd,进行 MyProject 目录,win10 下打开 MyProject 目录点击地址栏录入 cmd 可快速打开 cmd,并且目录为当前地址

3、执行 dotnet new webapi

C:\Users\28810\Desktop\MyProject>dotnet new webapi
已成功创建模板“ASP.NET Core Web API”。

正在处理创建后操作...
正在 C:\Users\28810\Desktop\MyProject\MyProject.csproj 上运行 "dotnet restore"...
  正在还原 C:\Users\28810\Desktop\MyProject\MyProject.csproj 的包...
  正在生成 MSBuild 文件 C:\Users\28810\Desktop\MyProject\obj\MyProject.csproj.nuget.g.props。
  正在生成 MSBuild 文件 C:\Users\28810\Desktop\MyProject\obj\MyProject.csproj.nuget.g.targets。
  C:\Users\28810\Desktop\MyProject\MyProject.csproj 的还原在 1.11 sec 内完成。

还原成功。

4、执行 dotnet add package FreeSql.Provider.Sqlite

5、执行 dotnet add package FreeSql.DbContext

6、创建几个常用的实体类,点击下载演示的实体类

7、确定项目可以编译通过

C:\Users\28810\Desktop\MyProject>dotnet build
用于 .NET Core 的 Microsoft (R) 生成引擎版本 15.9.20+g88f5fadfbe
版权所有(C) Microsoft Corporation。保留所有权利。

  C:\Users\28810\Desktop\MyProject\MyProject.csproj 的还原在 65.32 ms 内完成。
  MyProject -> C:\Users\28810\Desktop\MyProject\bin\Debug\netcoreapp2.2\MyProject.dll
  MyProject -> C:\Users\28810\Desktop\MyProject\bin\Debug\netcoreapp2.2\MyProject.Views.dll

已成功生成。
    0 个警告
    0 个错误

已用时间 00:00:01.82

8、执行 FreeSql.AdminLTE.Tools -Find MyProject.Model..+ -First

请开启项目 xml 文档生成功能,再执行此操作

9、运行项目,执行 dotnet run

Since this is a common webapi project, there is no open access static resources, so please modify Startup.cs in:

public class Startup
{
    public Startup()
    {
        Fsql = new FreeSql.FreeSqlBuilder()
            .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|/test.db;Pooling=true;Max Pool Size=5")
            .UseAutoSyncStructure(true)
            .Build();
    }
    public static IFreeSql Fsql { get; private set; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IFreeSql>(Fsql);
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
    {
        app.UseDeveloperExceptionPage();
        app.UseMvc();
        app.UseDefaultFiles();
        app.UseStaticFiles();
    }
}

10, open the browser to access the address-step tips, such as: http: // localhost: 57844 / adminlte / index.html

Sentiment

Does not like to use vue, in fact, I would use, said additional fine not proficient. . Just think vue small-scale operations quickly enough.

FreeSql.AdminLTE.Tools command line operation, can quickly generate a single batch or deletions check entity classes razor + modified method of the controller, the command is temporarily unable to support .net framework project, the project may be considered incorporated ASP.NET MVC custom library FreeSql.AdminLTE code generation.

FreeSql.AdminLTE subsequent updatable content is very small, small partner interest, the same model can be used to do FreeSql.ElementUI is also not possible, right? Anyway, there are FreeSql provide basic protection.

If used questions please leave a message, thank you!

github: https://github.com/2881099

Guess you like

Origin www.cnblogs.com/kellynic/p/11444176.html