ASP.NET CORE WEB API DEMO 02
2021-02-10 00:14
标签:book bad apt extension ctr net httpd otf XML ASP.NET CORE WEB API DEMO 02 标签:book bad apt extension ctr net httpd otf XML 原文地址:https://www.cnblogs.com/xiaowangzhi/p/8542983.htmlusing System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Demo.Models
{
public class BookChapter
{
public Guid Id { get; set; }
public int Number { get; set; }
public string Title { get; set; }
public int Pages { get; set; }
}
public interface IBookChaptersRepository
{
Task InitAsync();
Task
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Demo.Models;
using Microsoft.AspNetCore.Mvc;
namespace Demo.Controllers
{
[Produces("application/json", ("application/xml"))]
[Route("api/[controller]")]
public class BookChaptersController : Controller
{
private readonly IBookChaptersRepository _repository;
public BookChaptersController(IBookChaptersRepository bookChaptersRepository)
{
_repository = bookChaptersRepository;
}
// GET api/bookchapters
[HttpGet]
public Task
using Demo.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Demo
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddXmlSerializerFormatters();
IBookChaptersRepository repos = new BookChaptersRepository();
repos.InitAsync();
services.AddSingleton(repos);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}
上一篇:JQuery
文章标题:ASP.NET CORE WEB API DEMO 02
文章链接:http://soscw.com/index.php/essay/53315.html