Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cross Platform WebAPIs with ASP.NET Core

Cross Platform WebAPIs with ASP.NET Core

Slides for my talk about Cross Platform WebAPIs with ASP.NET Core

Fabian Gosebrink

October 22, 2017
Tweet

More Decks by Fabian Gosebrink

Other Decks in Technology

Transcript

  1. public class Program { public static void Main(string[] args) {

    BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); }
  2. Program.cs 1. public class Program 2. { 3. public static

    void Main(string[] args) 4. { 5. BuildWebHost(args).Run(); 6. } 7. 8. public static IWebHost BuildWebHost(string[] args) => 9. WebHost.CreateDefaultBuilder(args) 10. .UseStartup<Startup>() 11. .Build(); 12. }
  3. public class Program { public static void Main(string[] args) {

    var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } }
  4. Startup.cs 1. public class Startup 2. { 3. public Startup(IConfiguration

    configuration) 4. { 5. Configuration = configuration; 6. } 7. 8. public IConfiguration Configuration { get; set; } 9. 10. public void ConfigureServices(IServiceCollection services) 11. { 12. services.AddOptions(); 13. services.AddCors(...); 14. 15. services.AddSingleton<IFoodRepository, FoodRepository>();
  5. 2XX

  6. 4XX

  7. 5XX

  8. The Controller 1. [Route("api/[controller]")] 2. public class FoodController : Controller

    3. { 4. private readonly IFoodRepository _foodRepository; 5. 6. public FoodController(IFoodRepository foodRepository) 7. { 8. _foodRepository = foodRepository; 9. } 10. 11. [HttpGet] 12. public IActionResult Get() 13. { 14. ICollection<FoodItem> foodItems = _foodRepository.GetAll(); 15. IEnumerable<FoodItemDto> dtos = foodItems