Skip to content
Piyush D edited this page Jan 16, 2019 · 13 revisions

WebApiBoilerPlate wiki!

This project aims to become a template project that gets you started right away with a complete and secure backend. Below are some key design and architectural insights to help you under the code. Please read them once before diving into the code.

Api layer (Asp.Net Web API)

  • Web Api secured with OAuth2 using a custom OAuth server with few tweaks. Each API route is secured by role based Auth.
  • Automatically generated API documentation/help page which uses the Summary of each controller/class to generate the API documentation. It also features a TEST API button.
  • Throttling to prevent DOS attacks to some extent
  • Separate projects for Unit tests as well as Integration tests using NUnit runners.
  • Unity Container for Dependency resolution. Each project register their dependencies individually.

Business Service layer

  • Middle layer that sits between the API layer and the Database access layer.
  • All business logic needs to go in here
  • UnitOfWork pattern used to wrap a single business transaction
  • Automapper used to map Database models to DTO (Data transfer) models
  • Separate Unit tests project

Database layer (SQL server and CosmosDb)

  • Entity Framework Code first Migrations used to initialize and update the databases (SQL server and CosmosDb).
  • Repository pattern along with UnitOfWork gives the consumer (Business layer) complete control of the transactions (except for CosmosDb transactions)
  • Separate project for Database integration tests. (A new db is created, tests are run and the db gets delete every time)

Getting started

  • Search for "your from Visual Studio and a list of places where you need to enter you valid email Id, database connection and so on shows up. "your is the placeholder that I have used. Make those replacements.
  • Restore the Nuget packages and press F5
  • Open up the https://yourhost.com/help page to see the documentation for the API. You can also use the Test button to make API calls but I personally find using Postman more convenient.
  • Import the Postman samples from here

Note

  • My private repositories hold a more accomplished version of this project which includes Azure Web Jobs, Azure Blobs, CosmosDb connections (using repositories under unit of work). Plus all of that gets deployed to Azure App Service with every check-in which is quality controlled by a Gated-checkin on VSTS (Visual Studio team services).
  • I will try and add those components (at least the demos) in this repo moving forward