npm 包 generator-gmdotnetrest 使用教程

阅读时长 12 分钟读完

简介

generator-gmdotnetrest 是一个用于快速生成 ASP.NET Core WebApi 项目的 Yeoman 生成器,其中包含常用的库和配置,如 Swagger 和 AutoMapper 等。使用该生成器可以大大提高 ASP.NET Core WebApi 项目的开发效率。

安装

使用 npm 安装 generator-gmdotnetrest:

使用方法

新建一个空目录,进入该目录运行以下命令:

该命令会在当前目录下生成一个 ASP.NET Core WebApi 项目。

配置项

运行 yo gmdotnetrest --help 命令查看各配置项的含义:

-- -------------------- ---- -------
------
  -- ---------------- ---------

--------
  ---   ------               - ----- --- ----------- ------- --- -----
        ------------         - -- --- -------- ------ -------             -------- -----
        --------------       - -- --- ------------- ------- ------------  -------- -----
        --------             - -- --- ---------- - --- ----------          -------- -----
        ------ ------        - --- ---- -- --- -----------
        -------------       - --- ----------- -- --- -----------
        -------------       - --- ---- -- --- ------
        --------------      - --- ----- ------- -- --- ------
        ------------        - --- --- -- --- -------- -------
        ---------           - --- ------- ----
                              - ---------- ------- ----------- -------- ---
        --------------      - --- ------- ---- -- ------ --- -------------    -------- ---
        --------            - ------- -- ---------- - -------------------   -------- -----

示例代码

以下为生成的示例代码,其中包含了 Swagger 和 AutoMapper 的使用:

-- -------------------- ---- -------
----- -----------
----- -----------------------------
----- -----------------------------
----- -------------------------
----- ------------------------------
----- -----------------------------------
----- -----------------------------------------
----- -------------------------------
----- -------
----- ------------------

--------- --------
-
    ------ ----- -------
    -
        ------ ---------------------- --------------
        -
            ------------- - --------------
        -

        ------ -------------- ------------- - ---- -

        ------ ---- ------------------------------------ ---------
        -
            ------------------------------------------ --
                ------------------------------------------------------------------------------

            -----------------
                ----------------------------------------------------------
                ----------------------- --
                -
                    ------------------------------------------- - --- --------------------------------------------------------
                ---

            ------------------------------ --
            -
                ------------------------ --- ---- - ----- - --- --- ----- ------- - ---- ---
                --- ------- - --------------------------------------------------------
                --- ------- - ------------------------------------------------ ---------
                ------------------------------------
            ---

            ----------------------------------------

            ------------------------------------------ --
            -
                --------------------- - --------------------------------------
            ---
        -

        ------ ---- ----------------------------- ---- ------------------- ----
        -
            -----------------

            ------------------ --
            -
                ------------- - ----------
                --------------------------------------------- --- --- --- -----
                -------------------------------
            ---

            -- ---------------------
            -
                --------------------------------
            -

            -------------
        -
    -
-
-- -------------------- ---- -------
----- -----------
----- -------------------------
----- ------------------------------
----- ---------------------------
----- ------------
----- -----------------------

--------- --------------------
-
    ---------------------------
    ---------------
    ------ ----- --------------- - --------------
    -
        ------- -------- ----------- ---------
        ------- -------- ------- --------

        ------ --------------------------- -------- ------- -------
        -
            -------- - --------
            ------- - -------
        -

        ---------
        ------ ----- ---------------------------------------- ----------
        -
            --- ----- - ----- -----------------------------
            ------ ----------------------------------
        -

        -----------------
        ------ ----- --------------------------- ----------- ---
        -
            --- ---- - ----- -----------------------------

            -- ----- -- -----
            -
                ------ -----------
            -

            ------ ---------------------------
        -

        ----------
        ------ ----- --------------------------- ---------------------- --------------
        -
            --- ---- - ---------------------------------
            -------------------------
            ----- ----------------------------

            ------ -------------------------------- --- - -- - ------- -- ----------------------------
        -

        -----------------
        ------ ----- ------------------- ----------- --- ------------- --------------
        -
            -- --- -- -----------------
            -
                ------ -------------
            -

            --- ---- - ---------------------------------
            -------------------------- - ---------------------

            ---
            -
                ----- ----------------------------
            -
            ----- ------------------------------
            -
                -- -----------------
                -
                    ------ -----------
                -
                ----
                -
                    ------
                -
            -

            ------ ------------
        -

        --------------------
        ------ ----- --------------------------- -------------- ---
        -
            --- ---- - ----- -----------------------------
            -- ----- -- -----
            -
                ------ -----------
            -

            ----------------------------
            ----- ----------------------------

            ------ ---------------------------
        -

        ------- ---- -------------- ---
        -
            ------ -------------------- -- ---- -- ----
        -
    -

    ------ ----- -------
    -
        ------ --- -- - ---- ---- -
        ------ ------ ---- - ---- ---- -
    -

    ------ ----- -------------
    -
        ------ ------ ---- - ---- ---- -
    -

    ------ ----- -------------
    -
        ------ --- -- - ---- ---- -
        ------ ------ ---- - ---- ---- -
    -
-

总结

generator-gmdotnetrest 是一个非常实用的 Yeoman 生成器,用于快速生成 ASP.NET Core WebApi 项目。生成器包含了常用的库和配置,如 Swagger 和 AutoMapper 等,可以大大提高项目的开发效率。如果你正在开发 ASP.NET Core WebApi 项目,generator-gmdotnetrest 绝对是你不可或缺的开发工具。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/6005671981e8991b448e36f3

纠错
反馈