@manhng

Welcome to my blog!

ASP.NET Core Microservices with MongoDB

September 1, 2021 18:50

ASP.NET Core Microservices with MongoDB (edit)

  • MongoDB
  • Kafka
  • Microservices
  • ASP.NET Core

MongoDB and Data Streaming: Implementing a MongoDB Kafka Consumer - DZone Big Data

Data Streaming with Apache Kafka & MongoDB - EMEA (slideshare.net)

MongoDB Connector for Apache Kafka 1.5 Available Now | MongoDB

aspnetrun/run-aspnetcore-microservices: Microservices on .Net platforms which used Asp.Net Web API, Docker, RabbitMQ, MassTransit, Grpc, Ocelot API Gateway, MongoDB, Redis, PostgreSQL, SqlServer, Dapper, Entity Framework Core, CQRS and Clean Architecture implementation. Also includes Cross-Cutting concerns like Implementing Centralized Distributed Logging with Elasticsearch, Kibana and SeriLog, use the HealthChecks with Watchdog, Implement Retry and Circuit Breaker patterns with Polly and so on.. See Microservices Architecture and Step by Step Implementation on .NET Course w/ discount-> (github.com)

Whats Including In This Repository

We have implemented below features over the run-aspnetcore-microservices repository.

Catalog microservice which includes;

  • ASP.NET Core Web API application
  • REST API principles, CRUD operations
  • MongoDB database connection and containerization
  • Repository Pattern Implementation
  • Swagger Open API implementation

Basket microservice which includes;

  • ASP.NET Web API application
  • REST API principles, CRUD operations
  • Redis database connection and containerization
  • Consume Discount Grpc Service for inter-service sync communication to calculate product final price
  • Publish BasketCheckout Queue with using MassTransit and RabbitMQ

Discount microservice which includes;

  • ASP.NET Grpc Server application
  • Build a Highly Performant inter-service gRPC Communication with Basket Microservice
  • Exposing Grpc Services with creating Protobuf messages
  • Using Dapper for micro-orm implementation to simplify data access and ensure high performance
  • PostgreSQL database connection and containerization

Microservices Communication

  • Sync inter-service gRPC Communication
  • Async Microservices Communication with RabbitMQ Message-Broker Service
  • Using RabbitMQ Publish/Subscribe Topic Exchange Model
  • Using MassTransit for abstraction over RabbitMQ Message-Broker system
  • Publishing BasketCheckout event queue from Basket microservices and Subscribing this event from Ordering microservices
  • Create RabbitMQ EventBus.Messages library and add references Microservices

Ordering Microservice

  • Implementing DDD, CQRS, and Clean Architecture with using Best Practices
  • Developing CQRS with using MediatR, FluentValidation and AutoMapper packages
  • Consuming RabbitMQ BasketCheckout event queue with using MassTransit-RabbitMQ Configuration
  • SqlServer database connection and containerization
  • Using Entity Framework Core ORM and auto migrate to SqlServer when application startup

API Gateway Ocelot Microservice

  • Implement API Gateways with Ocelot
  • Sample microservices/containers to reroute through the API Gateways
  • Run multiple different API Gateway/BFF container types
  • The Gateway aggregation pattern in Shopping.Aggregator

WebUI ShoppingApp Microservice

  • ASP.NET Core Web Application with Bootstrap 4 and Razor template
  • Call Ocelot APIs with HttpClientFactory and Polly

Microservices Cross-Cutting Implementations

  • Implementing Centralized Distributed Logging with Elastic Stack (ELK); Elasticsearch, Logstash, Kibana and SeriLog for Microservices
  • Use the HealthChecks feature in back-end ASP.NET microservices
  • Using Watchdog in separate service that can watch health and load across services, and report health about the microservices by querying with the HealthChecks

Microservices Resilience Implementations

  • Making Microservices more resilient Use IHttpClientFactory to implement resilient HTTP requests
  • Implement Retry and Circuit Breaker patterns with exponential backoff with IHttpClientFactory and Polly policies

Ancillary Containers

  • Use Portainer for Container lightweight management UI which allows you to easily manage your different Docker environments
  • pgAdmin PostgreSQL Tools feature rich Open Source administration and development platform for PostgreSQL

Docker Compose establishment with all microservices on docker;

  • Containerization of microservices
  • Containerization of databases
  • Override Environment variables

What you'll learn

  • ASPNET Core Web API Development of Microservices
  • REST API Principles, CRUD Operations
  • Mongo DB and Redis NoSQL Database Connection on Docker
  • Entity Framework Core with SQL Server Database Connection on Docker
  • N-Layer implementation with Repository Pattern
  • Swagger Open API implementation
  • Consume Discount Grpc Service for inter-service sync communication to calculate product final price
  • Publish BasketCheckout Queue with using MassTransit and RabbitMQ
  • Build a Highly Performant inter-service gRPC Communication with Basket Microservice
  • Using Dapper for micro-orm implementation to simplify data access and ensure high performance
  • PostgreSQL database connection and containerization
  • Async Microservices Communication with RabbitMQ Message-Broker Service
  • Using RabbitMQ Publish/Subscribe Topic Exchange Model
  • Using MassTransit for abstraction over RabbitMQ Message-Broker system
  • Implementing DDD, CQRS, and Clean Architecture with using Best Practices
  • Developing CQRS with using MediatR, FluentValidation and AutoMapper packages
  • Consuming RabbitMQ BasketCheckout event queue with using MassTransit-RabbitMQ Configuration
  • Using Entity Framework Core ORM and auto migrate to SqlServer when application startup
  • Ocelot API Gateway Development of Microservices
  • Call Ocelot APIs with HttpClientFactory
  • The Gateway aggregation pattern in Shopping Aggregator
  • ASPNET Core Web Application with Bootstrap 4 and Razor template
  • Docker Compose Containerization of All Microservices
  • Use Portainer for Container lightweight management UI which allows you to easily manage your different Docker environments
  • pgAdmin PostgreSQL Tools feature rich Open Source administration and development platform for PostgreSQL

Mapping Generator

August 8, 2021 21:58

Mapping Generator (edit)

MappingGenerator was initially created as a design-time alternative to AutoMapper. Now it is evolving into a coding assistant to whom you can delegate the most mundane coding tasks.

Alternative to AutoMapper

MappingGenerator - Visual Studio Marketplace

A Simple and Fast Object Mapper (HAY HAY HAY)

Nuget: Boxed.Mapping

A Simple and Fast Object Mapper - Muhammad Rehan Saeed

AutoMapper Usage Guidelines

Nuget: AutoMapper

AutoMapper Usage Guidelines (jimmybogard.com)

Adding errors to model state and returning bad request within asp.net core 3.1

Adding errors to model state and returning bad request within asp.net core 3.1 - Developer Ramblings of Kevin Smith (kevsoft.net)

Paging data in MongoDB with C#

Paging data in MongoDB with C# - Developer Ramblings of Kevin Smith (kevsoft.net)

Storing GUIDs as strings in MongoDB with C#

Storing GUIDs as strings in MongoDB with C# - Developer Ramblings of Kevin Smith (kevsoft.net)

Managing Relationships With Dapper

Managing Relationships With Dapper | Learn Dapper

OpenIdDict MongoDB

July 28, 2021 16:04

OpenIdDict MongoDB (edit)

  • ASP.NET Core 5.0 & ASP.NET Core 5.0 Web API
  • OpenIddict 3.0
  • MongoDB
  • OAuth2 + OpenID Connect

Introduction (openiddict.com) This project is licensed under the Apache License

Openiddict-core Alternatives and Similar Projects (Jun 2021) (libhunt.com) (HAY HAY HAY)

Best 20 NuGet mongodb Packages - NuGet Must Haves Package (HAY HAY HAY)

Versatile OpenID Connect stack for ASP.NET Core 2.1/3.1/5.0 and Microsoft.Owin 4.2 (compatible with ASP.NET 4.6.1)

OpenIddict aims at providing a simple and easy-to-use solution to implement an OpenID Connect server in any ASP.NET Core 1.x or 2.x application. OpenIddict is based on AspNet.Security.OpenIdConnect.Server (codenamed ASOS) to control the OpenID Connect authentication flow and can be used with any membership stack, including ASP.NET Core Identity.

openiddict/openiddict-core: Versatile OpenID Connect stack for ASP.NET Core 2.1/3.1/5.0 and Microsoft.Owin 4.2 (compatible with ASP.NET 4.6.1) (github.com) (HAY HAY HAY)

This is a sample blazor project demonstrating the use of openiddict-core with AspNetCore.Identity and AspNetCore.Identity.MongoDbCore

weirdyang/openiddict-mongodb-identity (github.com) (HAY HAY HAY)

NuGet Gallery | OpenIddict.MongoDb 3.1.0

c# - .NET Core configure OpenIddict with MongoDb - Stack Overflow

.net core - SSO with openiddict set login page absolute url - Stack Overflow

Prevent redirect to /Account/Login in asp.net core 2.2 - Stack Overflow

MongoDB Data Store Adaptor for ASP.NET Core Identity

tugberkugurlu/AspNetCore.Identity.MongoDB: MongoDB Data Store Adaptor for ASP.NET Core Identity (github.com) (HAY HAY HAY)

IMPLEMENTING OPENID CODE FLOW WITH PKCE USING OPENIDDICT AND ANGULAR

Implementing OpenID Code Flow with PKCE using OpenIddict and Angular | Software Engineering (damienbod.com)

OpenIddict Angular ASP.NET Core OpenID Connect Code Flow with PKCE

damienbod/AspNetCoreOpeniddict: OpenIddict Angular ASP.NET Core OpenID Connect Code Flow with PKCE (github.com) (HAY HAY HAY)

Setting up an Authorization Server with OpenIddict

Setting up an Authorization Server with OpenIddict - Part I - Introduction - DEV Community

Authorization Server implemented with OpenIddict

robinvanderknaap/authorization-server-openiddict: Authorization Server implemented with OpenIddict. (github.com) (HAY HAY HAY)

Implementing an OpenIddict Authorization server: A Basic Authorization Server

Implementing an OpenIddict Authorization server: A Basic Authorization Server | Jerrie Pelser's Blog

dotnet add package AspNet.Security.OAuth.Validation
dotnet add package OpenIddict
dotnet add package OpenIddict.Mvc
dotnet add package OpenIddict.EntityFrameworkCore

ASP.NET Core and MongoDB

July 25, 2021 16:05

ASP.NET Core and MongoDB (edit)

Cloud: AWS

Configuring the AWS SDK for .NET with .NET Core - AWS SDK for .NET (version 3) (amazon.com)

NuGet Packages:

+ AWSSDK.S3 (Amazon Simple Storage Service (Amazon S3), provides developers and IT teams with secure, durable, highly-scalable object storage.)

+ AWSSDK.Extensions.NETCore.Setup (Extensions for the AWS SDK for .NET to integrate with .NET Core configuration and dependency injection frameworks.)

AWSSDK.DynamoDBv2 (Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale.)

AWSSDK.CognitoIdentity (Amazon Cognito is a service that makes it easy to save user data, such as app preferences or game state, in the AWS Cloud without writing any backend code or managing any infrastructure. With Amazon Cognito, you can focus on creating great app experiences instead of having to worry about building and managing a backend solution to handle identity management, network state, storage, and sync.)

Amazon Cognito: User Identity Management

Successful web or mobile applications can reach millions of users, and it is critical that such applications have a robust and scalable approach for user and identity management.

Applications can have specific requirements, such as using their own identity store, or leveraging an existing identity provider such as Facebook, Google, or Amazon. Some need to use a combination of their own identity store with existing identity providers. This is often coupled with requirements for a user interface that handles user registration, login, user verification, and forgotten passwords.

Amazon Cognito enables you to add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. Amazon Cognito scales to millions of users and supports sign-in with social identity providers, including Facebook, Google, and Amazon, and enterprise identity providers via SAML 2.0.

Amazon Cognito can also be used to control access to REST APIS through integration with the Amazon API Gateway service, and can reduce the work to authenticate web application users by integrating with
the Application Load Balancer.

Security features include multi-factor authentication, checks for compromised credentials, account takeover protection, and phone and email verification. Amazon Cognito also supports application specific identity stores, user profiles, and customized workflows and user migration through Lambda triggers.

+ ASP.NET Core Identity for Amazon Cognito

Introducing the ASP.NET Core Identity Provider Preview for Amazon Cognito | AWS Developer Tools Blog

aws/aws-aspnet-cognito-identity-provider: ASP.NET Core Identity Provider for Amazon Cognito (github.com)

DB: MongoDB

MongoDB - How to backup and restore a database | Jason Watmore's Blog

Client: React JS Boilerplate

cornflourblue/react-signup-verification-boilerplate: React Boilerplate - Email Sign Up with Verification, Authentication & Forgot Password (github.com)

Framework: Open Source ASP.NET Core 5.0 Web API

vb-software/netcore-webapi-starter: .NET Core Web API Starter Template (github.com)

Article:

Build a Basic CRUD App with ASP.NET Core 3.0 and MongoDB | Okta Developer

Tag:

ASP.NET Core 3.1 - Role Based Authorization Tutorial with Example API | Jason Watmore's Blog

Idea:

c# - Simple token based authentication/authorization in asp.net core for Mongodb datastore - Stack Overflow

Authentication/Authorization:

Node + Mongo - Boilerplate API with Email Sign Up, Verification, Authentication & Forgot Password | Jason Watmore's Blog

  • Email sign up and verification
  • JWT authentication with refresh tokens
  • Role based authorization with support for two roles (User & Admin)
  • Forgot password and reset password functionality
  • Account management (CRUD) routes with role based access control
  • Swagger api documentation route

Node.js + MongoDB API - JWT Authentication with Refresh Tokens | Jason Watmore's Blog

ASP.NET Core 3.1 API - JWT Authentication with Refresh Tokens | Jason Watmore's Blog

MongoDB

January 25, 2019 11:38

MongoDB (edit)

MongoDB Transactions

Working with MongoDB Transactions with C# and the .NET Framework

Software's needed:

Samples

yogyogi/First-ASP.NET-Core-Microservice: First ASP.NET Core Microservice with Web API CRUD Operations on a MongoDB database [Clean Architecture] (github.com)

fpetru/WebApiMongoDB: Using MongoDB with ASP.NET Web API and ASP.NET Core to perform CRUD operations and build a NotebookApp (github.com)

C# and MongoDB Delete Operation

C# and MongoDB Delete Operation (github.com)

First ASP.NET Core Microservice with Web API CRUD Operations on a MongoDB database [Clean Architecture]

First ASP.NET Core Microservice with Web API CRUD Operations on a MongoDB database [Clean Architecture] (hosting.work)

Getting Started with ASP.NET Core and MongoDB

Getting Started with ASP.NET Core and MongoDB - Code Maze (code-maze.com)

ASP.NET Core series

.NET Core Tutorial - Creating the restful Web API - Code Maze (code-maze.com)

ASP.NET Core Microservices series

This tutorial is a part of ASP.NET Core Microservices series. It contains the following tutorials:

CRUD Operations Using ASP.NET Web API, MongoDB, and Angular 8

  • Angular 8
  • CRUD
  • MongoDB
  • ASP.NET Core WEB API
  • Cross-Origin Resource Sharing (CORS)

CRUD Operations Using ASP.NET Web API, MongoDB, and Angular 8 - DZone Web Dev

Terminology and Concepts

If you're not familiar with MongoDB, here's a quick translation cheat sheet to get you familiar with the terminology.

SQL Server MongoDB
Database Database
Table Collection
Index Index
Row Document
Column Field
Joining Linking & Embedding
Partition Sharding (Range Partition)
Replication ReplSet

Categories

Recent posts