From
to a dockerized CI/CD
Vedran Mandić, MCSD, MCSA, MCT
#ATD15, Zagreb 2019-12-05
dotnet new webapi
...with integration tests
Thank you sponsors
Hi, I am Vedran. 👋
- I freelance, talk and lecture C# / .NET and JavaScript
- currently in insurance industry
- on medium and dev.to by @vekzdran
- on github by @vmandic
- bad at basics, suck at CSS, moderate in C#... jk 🙈
What's this presentation about?
Today's plan?
- (ASP).NET Core super quick overview
- No Visual Studio IDE?
- API Design, REST, DDD, Swagger?
- demo up a web API with code 👩💻
- host the demo to a CI/CD provider
First a bit of .NET Core
.NET Core, an overview
- open-source (GitHub) cross-platform Runtime and SDK
- Current release is 3.1 (Dec 3 2019), started in 2015
- modern, stable, performing, modular, extensible
- you can fix bugs, suggest PRs, report issues, ... FIND ANSWERS :-)
- it is a complete rewrite of .NET Framework; its Core libraries
- introduced .NET Standard, run side by side with Full framework
- integrated DI/IoC, Builder pattern, logging, configuration
- extends with ASP.NET Core, ASP.NET Identity, MVC, Razor Pages, Blazor, EFCore... just search NuGet.org and you got it...
- you can compile for a dedicated OS, e.g. linux-x64
- you can compile the whole framework /w app as single .exe
ASP.NET Core?
ASP.NET Core
- a set of APIs, libraries for building a web apps and services
- APIs come either separately or in AspNetCore Metapackage
- comes with its own new server Kestrel, also HTTP.sys
- can host in IIS, outside it, behind a reverse proxy e.g. Nginx
- expands design on the OWIN architecture
- Startup.cs, ConfigureService(), Configure()
- Go full MVC with filters etc, or go Web API with ControllerBase
- Razor view, Razor pages, Blazor server side-by-side with Razor
- compile the app as self-executable and host on any linux server
by the way... we will be building a web API today
$ dotnet new webapi
what's to like?
lol, what's not to like?! :-)
what's to like?
- dotnet CLI... and dotnet tools!
- fast builds, logs everything!
- stability, performance and openness for extensiblity
- fantastic docs and GitHub support
- learn from MSDN docs 80%, 10% from blogs, and 10% from XP
- my XP: 1 month for basics, 6 months to feel safe
- great community, lots of books, blogs
- widespread (open-source) NuGet packages, supported
- cross-plat and docker friendly, CI/CD happy
- I learned to appreciate and harness the CLI and linux
Visual Studio IDE?
- there is... Visual Studio 2017, 2019 and they are better then ever
- Instead try the open source community VSCode
- embrace the dotnet CLI, reference projects faster ;-)
- VSCode is an editor with a ton of extensions and C# support
- currently I use Visual Studio IDE only for multi test debugging
- https://visualstudio.microsoft.com/services/visual-studio-online/
Visual Studio Code
Considerations to take when building an API
possibly > decimal.MaxValue
that's 79,228,162,514,264,337,593,543,950,335 things to think about...
Some things to consider in API design
- exhaustive logging
- healthcheck API
- REST(ful) (as much as possible...🙈) HATEOAS
- API Documentation (Swagger OpenAPI)
- CORS policy
- full control over in and out HTTP headers
- versioned, rate limited, cached...
- Authentication with JWT and claims
- Multi-authentication
- Fail unobtrusively and redact error details
- logic independent to scaling (ACS, k8s, OpenShift pods++)
- Clean Code, Domain Driven Design layered...
- Open-Closed, SRP, pure as much as possible...
- Testable, Integration testable, CI/CD-able
That's what you should love about .NET Core, all of it's plug and play
Also Luka Gospodnetić had a wonderful great talk about it yesterday:
"Through desert and wilderness to .NET Core Enterprise app"
Swagger (OpenAPI)
- solves the problem of API documentation
- it is a .json which describes your API: methods & models
- Swashbuckle.AspNetCore & NSwag solve generating the .json
- Swashbuckle generates a freindly web Swagger-UI to for testing
-
https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger
- Example: https://petstore.swagger.io/
demo time!
more sort of a code-review than coding :-)
The end! 📸 Questions?
VEDRAN MANDIĆ
mandic.vedran@gmail.com
@vekzdran @vmandic
https://gitlab.com/vmandic/from-dotnet-new-webapi
https://slides.com/vmandic/from-dotnet-new-webapi
From dotnet new webapi to a dockerized CI/CD
By Vedran Mandić
From dotnet new webapi to a dockerized CI/CD
A short but succinct guide in building a simple but secure and dockerized .NET Core Web API solution.
- 931