当前位置: 首页 > 软件库 > 云计算 > >

dotnet-api-boilerplate

授权协议 MIT License
开发语言 Java
所属分类 云计算
软件类型 开源软件
地区 不详
投 递 者 梁楷
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

dotnet-api-boilerplate

A .Net 5.0 WebApi boilerplate / template project. Repositories, Swagger, Mapper, Serilog and more implemented.

Build

The goal of this project is to be a kickstart to your .Net WebApi, implementing the most common used patternsand technologies for a restful API in .net, making your work easier.

How to run

  • Use this template(github) or clone/download to your local workplace.
  • Download the latest .Net SDK and Visual Studio/Code.

Standalone

  1. You may need a running instance of MsSQL, with appropriate migrations initialized.
    • You can run just the DB on docker. For that, you have to change your connection string to "Server=127.0.0.1;Database=master;User=sa;Password=Yourpassword123” and run the following command: docker-compose up -d db-server. Doing that, the application will be able to reach de container of the db server.
    • If you want, you can change the DatabaseExtension to use UseInMemoryDatabase, instead of Mssql.
  2. Go to the src/Boilerplate.Api folder and run dotnet run, or, in visual studio set the api project as startup and run as console or docker (not IIS).
  3. Visit http://localhost:5000/api-docs or https://localhost:5001/api-docs to access the application's swagger.

Docker

  1. Run docker-compose up -d in the root directory, or, in visual studio, set the docker-compose project as startup and run. This should start the application and DB.
    1. For docker-compose, you should run this command on the root folder: dotnet dev-certs https -ep https/aspnetapp.pfx -p yourpasswordReplace "yourpassword" with something else in this command and the docker-compose.override.yml file.This creates the https certificate.
  1. Visit http://localhost:5000/api-docs or https://localhost:5001/api-docs to access the application's swagger.

Running tests

In the root folder, run dotnet test. This command will try to find all test projects associated with the sln file.

This project contains:

  • SwaggerUI
  • EntityFramework
  • AutoMapper
  • Generic repository (to easily bootstrap a CRUD repository)
  • Serilog with request logging and easily configurable sinks
  • .Net Dependency Injection
  • Resource filtering
  • Response compression
  • Response pagination
  • CI (Github Actions)
  • Unit tests
  • Integration tests
  • Container support with docker and docker-compose

Project Structure

  1. Services
    • This folder stores your apis and any project that sends data to your users.
    1. Boilerplate.Api
      • This is the main api project. Here are all the controllers and initialization for the api that will be used.
    2. docker-compose
      • This project exists to allow you to run docker-compose with Visual Studio. It contains a reference to the docker-compose file and will build all the projects dependencies and run it.
  2. Application
    • This folder stores all data transformations between your api and your domain layer. It also contains your business logic.
  3. Domain
    • This folder contains your business models, enums and common interfaces.
    1. Boilerplate.Domain.Core
      • Contains the base entity for all other domain entities, as well as the interface for the repository implementation.
    2. Boilerplate.Domain
      • Contains business models and enums.
  4. Infra
    • This folder contains all data access repositories, database contexts, anything that reaches for outside data.
    1. Boilerplate.Infrastructure
      • This project contains the dbcontext, an generic implementation of repository pattern and a Hero(domain class) repository.

Adopting to your project

  1. Remove/Rename all hero related stuff to your needs.
  2. Rename solution, projects, namespaces, and ruleset to your use.
  3. Change the dockerfile and docker-compose.yml to your new csproj/folder names.
  4. Give this repo a star!

Migrations

  1. To run migrations on this project, run the following command on the root folder:

    • dotnet ef migrations add InitialCreate --startup-project .\src\Boilerplate.Api\ --project .\src\Boilerplate.Infrastructure\
  2. This command will set the entrypoint for the migration (the responsible to selecting the dbprovider { sqlserver, mysql, etc } and the connection string) and the project itself will be the infrastructure, which is where the dbcontext is.

If you like it, give it a Star

If this template was useful for you, or if you learned something, please give it a Star!

Thanks

This project has great influence of https://github.com/lkurzyniec/netcore-boilerplate and https://github.com/EduardoPires/EquinoxProject. If you have time, please visit these repos, and give them a star, too!

About

This boilerplate/template was developed by Yan Pitangui under MIT license.

  • DotNet 资源大全 原文: DotNet 资源大全 转自:http://blog.jobbole.com/96676/ API 框架 NancyFx:轻量、用于构建 HTTP 基础服务的非正式(low-ceremony)框架,基于.Net 及 Mono 平台。 ASP.NET WebAPI:快捷创建 HTTP 服务的框架,可以广泛用于多种不同的客户端,包括浏览器和移动设备。 ServiceSt

  • (此文章同时发表在本人微信公众号“dotNET每日精华文章”,欢迎右边二维码来关注。) 题记:ABP经过2年多的开发,终于发布第一个主要版本了,谨此提醒ABP的使用者。 ASP.NET Boilerplate之前顺带介绍过两次。下面直接摘抄一点阳铭的介绍(http://www.cnblogs.com/mienreal/p/4528641.html): ABP是“ASP.NET Boilerplat

 相关资料
  • 这是 .NET 平台对Google API的封装,包括:搜索、翻译等;这是非官方的开发包。 示例代码: string text = "我喜欢跑步。"; TranslateClient client = new TranslateClient(/* Enter the URL of your site here */); string translated = client.Translate(te

  • dotNet Protector是一个功能强大的.NET代码保护系统,它可以防止程序集被反编译。dotNet Protector使用的是一个新的主体混淆技术保护应用程序和组件。程序集不再需要合并到一个win32可执行文件中,但是会保留其.net特性。 dotNet Protector 采用一个命名混淆器结合一个主体混淆器来保护您的代码。 dotNet Protector 本地运行支持X32、X64

  • Playwright for .NET �� Linux macOS Windows Chromium 94.0.4595.0 ✅ ✅ ✅ WebKit 15.0 ✅ ✅ ✅ Firefox 91.0 ✅ ✅ ✅ Playwright for .NET is the official language port of Playwright, the library to automate Chro

  • GraphQL for .NET This is an implementation of Facebook's GraphQL in .NET. Now the specification is being developed by theGraphQL Foundation. This project uses a lexer/parser originally writtenby Marek

  • What's new with Bot Framework This repository contains code for the .NET version of the Microsoft Bot Framework SDK, which is part of the Microsoft Bot Framework - a comprehensive framework for buildi

  • MySQL ASP.NET 5.0 Convert an ASP.NET Core Web Application project to use MySQL with Entity Framework, enabling development on macOS, linux, or Windows targets using IDEs such as VS Code, Visual Studio