loading...

MongoDB Web-Api Starter Template For `dotnet new`

github logo ・1 min read

I've developed a dotnet new starter template for scaffolding a web-api project with mongodb. It was designed with ease of development and maintenance in mind. The level of complexity of the architecture is extremely low compared to what you'd typically see with N-tier architecture. The code should be self explanatory. It comes with some commonly used features such as:

  • 3 Tier architecture
  • JWT token based authentication
  • Claim/Role/Policy based authorization
  • Input validation
  • Password hashing
  • Email sending
  • Image uploading
  • Strongly-typed app settings
  • Integration tests

You can see the source code from the github repository below or simply install and scaffold a new project to play with using the following code:

    dotnet new -i MongoWebApiStarter
    dotnet new mongowebapi -n MyAwesomeApp

GitHub logo dj-nitehawk / MongoWebApiStarter

A full-featured starter template for dotnet new to quickly scaffold a .Net Core 3.1 Web-Api project with MongoDB as the data store.

MongoWebApiStarter

A full-featured starter template for dotnet new to quickly scaffold a .Net Core 3.1 Web-Api project with MongoDB as the data store.

Install & Scaffold

  dotnet new -i MongoWebApiStarter
  dotnet new mongowebapi -n MyAwesomeApp

Features

Platform

  • framework: .net core 3.1
  • language: c#
  • database: mongodb

3 Layer Architecture

  • a single layer only references the layer immediately below it.
  • a layer has no idea about what's consuming it.

Api Layer

  • strongly typed app settings
  • JWT token authentication
  • policy based authorization
  • custom middleware for putting site offline (maintenance mode)

Business Layer

  • input validation with fluentvalidation rules
  • account creation, email validation, login
  • salted hash password storage and verification with bcrypt
  • email queue with background service for sending emails with smtp
  • image uploading

Data Layer

  • data access done using mongodb.entities library
  • data is modified & retrieved via repository classes

Integration Tests

  • uses mstest framework
  • uses fluentassertions
  • tests business logic via controller actions
twitter logo DISCUSS
Classic DEV Post from Jun 6 '19

What programming best practice do you disagree with?

Discussion about an unusual interview question

Đĵ ΝιΓΞΗΛψΚ profile image
Developer @ ChangeMon.com (Change Detection & Notification Service)

dev.to now has dark theme. 🌝

Go to the "misc" section of your settings and select night theme

P.S. It's the best move you can make for your dev career.