圖文說明,注意流量.數據庫
建好以後就像下面這樣
json
繼續再創建兩個.net core類庫項目分別是 ApiStudy.Core
和 ApiStudy.Infrastructure
api
一個解決方案下三個項目:瀏覽器
StartUp
類代碼namespace ApiStudy.api { using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); //使用默認路由 } } }
用來向容器中註冊服務,註冊好的服務能夠在其餘地方進行調用.markdown
用來配置中間件管道,即如何響應http請求.
app
代碼以下:網站
namespace ApiStudy.Api.Controllers { using Microsoft.AspNetCore.Mvc; [Route("api/[controller]")] [ApiController] public class UserController:Controller { public IActionResult Get() { return Ok("Hello"); } } }
修改lauchSetting.json以下:ui
{ "profiles": { "ApiStudy.api": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
瀏覽器訪問 https://localhost:5001/api/user
this