- Right-click and select Markup TOC Insert/update. Delete and update it
- Each First heading is a solution
- https://localhost:44307/ebook/doc
- https://localhost:44307/ebook/pdf
- https://localhost:44307/ebook/excel
- https://localhost:44307/ebook/zip
Hsoting a WebAPI project in a console application
- Create a console application
- Install the nuget package
- Create Controller and Model classes
- Configure self host in program.cs
- Write Console application to get data from the WebAPI
- Microsoft.AspNet.WebApi.SelfHost --> Web API
- Microsoft.AspNet.WebApi.Client --> Client
- http://localhost:8080/api/book?author=aroan
- http://localhost:8080/api/book/1
- http://localhost:8080/api/book
- https://www.c-sharpcorner.com/UploadFile/a6fd36/understand-self-host-of-a-web-apiC-Sharp/
- https://www.c-sharpcorner.com/uploadfile/a6fd36/understanding-how-to-call-the-web-api-from-a-client-applica/
- The different layers are
- API / Application / Presentation Layer
- Entry point into the application
- Exposes endpoints / UI and enforces validation
- No Business Logic
- Domain Model Layer
- Heart of the software
- Contains Business rules, logic and operations
- Infrastructure Layer
- Provides infrastructure plumbing
- Primary responsibility is persistence of business state
- API / Application / Presentation Layer
- ProducesResponseType → used as an attribute which is used in documentation like swagger providing information like response http status code and the return object.
[ProducesResponseType((int)HttpStatusCode.NotFound)] [ProducesResponseType(typeof(Product), (int)HttpStatusCode.OK)]
depends_onin docker file does not make sure that the dependant container is running properly. It just ensures that the dependant containers are started first.- Use mongoclient docker image to view the mongo data in GUI
docker run -d -p 3000:3000 mongoclient/mongoclient
- Redis → REmote DIctionary Server
- The below command is used to connect to redis in the bash
redis-cli - Command Redis command
ping set get
- Docker commands
docker exec -it shoppingcart-redis /bin/bash
- Portainer is a container management tool.
- credentials: admin/password
- pgadmin is used for postgresql administration.
- credentials: [email protected]/password
- gRPC → Google Remote Procedure Call
- gRPc uses HTTP/2 protocol and it is non-browser at the moment.
- DDD has the below layers
- Domain Model Layer
- Ideally, it must NOT take dependency on any other layer
- it Implements
- Domain Entities
- Repository Interfaces
- Application Layer
- Depends on Domain Layer for Domain entities and repository interfaces
- Depends on Infrastructure layer thru DI
- Infrastructure Layer
- Depends on Domain Layer for domain entities
- Direct dependency on infrastructure frameworks like EF core or any other database, cache or infrastructure API
- Domain Model Layer
- Qualities for Clean Architecture
- Framework independence
- Testability
- UI Independence
- Database Independence
- External Agency Independence
- CQRS → Command Query Responsibility Segregation
- New learning of mapper method
_mapper.Map(request, orderToUpdate, typeof(UpdateOrderCommand), typeof(Order));
- Configure to a particular config section
services.Configure<EmailSettings>(c => configuration.GetSection("EmailSettings"));
- GetService() returns null if a service does not exist, GetRequiredService() throws an exception instead. If you're using a third-party container, use GetRequiredService where possible - in the event of an exception, the third party container may be able to provide diagnostics so you can work out why an expected service wasn't registered.
- Microservices Communication Types
- Request driven architecture
- services communicate using http/rpc
- Clear control of flow. Easy to understand the sequence of actions.
- Drawback is if one of the dependant service is down, there is a high chance to exclude that call.
- Event driven architecture
- Services do not call each other. Communication happens over message broker.
- Consumers and providers does not know each other. So they can be maintained and deployed independently.
- Someone should understand without looking thru the code.
- Hybrid architecture
- Request driven architecture
- Properties of a queue
- Name
- Durable
- Exclusive
- AutoDelete
- Exchange Types
- Direct Exchanges
- Messages are sent to one queue
- Topic Exchanges
- Messages are sent to multiple queues
- variation of publish / subscribe pattern
- Fanout Exchanges
- Messages sent to more than one queue
- For broadcasting
- Header Exchanges
- Direct Exchanges
- Gateway Routing pattern (Ocelot)
- Routing / Reverse Proxy
- Data Aggregator / Request Aggregator
- Protocol Abstraction / Service Discovery with consul & Eureka
- Centralized Error Management / Logging and Tracing
- Load Balancing
- Correlation pass-through
- Quality of service
- Authentication
- Authorization
- Throttling
- Headers / Query String Transformation
- Custom Middleware
- Gateway Aggregation pattern
- Single Request
- Multiple calls to different backend systems
- Dispatches requests to the various backend systems
- Reduce chattiness between the client and the services
- Chaining HTTP calls is an antipattern
- Download the code from https://github.com/aspnetrun/run-aspnetcore-microservices
- Extract and traverse to that path (src folder which has the docker file) in Powershell
- Run the below command in Powershell to build and run the docker image
docker-compose -f docker-compose.yml -f docker-compose.override.yml up -d
- Create a new project Catalog.API with the template ASP.NET Core Web API.
- Change the running port and url
- Right-click on the project and go to properties.
- Go to Debug tab.
- Select Catalog.API from the profile.
- Check the app url at the bottom.
- The new profile gets added in the launchsettings.json in properties folder.
- Setup Mongo docker database
- Go to hub.docker.com
- Search for Mongo official database
- Right-click the solution and click on Open in Terminal. This will open up the Dveloper Powershell in the visual studio
- Run the below command to check whether any docker image is present and running
docker ps
- Run the below command to pull the docker image
docker pull mongo
- Run the below command to run the docker image
-d → runs the docker image in detached mode -p {image port in the container}:{forwarding port to the local computer}
docker run -d -p 27017:27017 --name shopping-mongo mongo
- Run the below command to check the logs
docker logs -f shopping-mongo
- Run the below command to get into interactive mode to check the mongo db
-it → interactive mode /bin/bash → runs bash
docker exec -it shopping-mongo /bin/bash
- Run the below command to get the list of databases
show dbs
- Run the below command to create the catalog database
use CatalogDb db.createCollection('Products') db.Products.insertMany([{ 'Name':'Asus Laptop','Category':'Computers', 'Summary':'Summary', 'Description':'Description', 'ImageFile':'ImageFile', 'Price':54.93 }, { 'Name':'HP Laptop','Category':'Computers', 'Summary':'Summary', 'Description':'Description', 'ImageFile':'ImageFile', 'Price':88.93 } ]) db.Products.find({}).pretty() db.Products.remove({}) show databases show collections db.Products.find({}).pretty()
- Run the below command to get the list of databases
- Install MongoDB.Driver nuget package
- Create docker compose file
- Right-click the project
- Go to Add > Add container Orchestrator support
- Select Docker compose and click ok
- Select Target OS as Linux
- DockerFile will be created in the project
- Docker compose will be created in the solution level
- Execute the below command to run the docker container
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d
- Execute the below command to stop the docker container.
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml down
- Create a new project Basket.API with the template ASP.NET Core Web API.
- Change the running port and url
- Right-click on the project and go to properties.
- Go to Debug tab.
- Select Basket.API from the profile.
- Check the app url at the bottom.
- The new profile gets added in the launchsettings.json in properties folder.
- Execute the below command to pull Redis
docker pull redis
- Run Redis container using the following command:
docker run -d -p 6379:6379 --name shoppingcart-redis redis
- Install the nuget package - Microsoft.Extensions.Caching.StackExchange
- Install the nuget package - Newtonsoft.Json
- Create docker compose file
- Right-click the project
- Go to Add > Add container Orchestrator support
- Select Docker compose and click ok
- Select Target OS as Linux
- DockerFile will be created in the project
- Docker compose will be updated
- Execute the below command to run the docker container
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d
- Create a new project Discount.API with the template ASP.NET Core Web API.
- Change the running port and url
- Right-click on the project and go to properties.
- Go to Debug tab.
- Select Discount.API from the profile.
- Check the app url at the bottom.
- The new profile gets added in the launchsettings.json in properties folder.
- Execute the below command to pull postgresql
docker pull postgres
- Execute the below command to pull pgadmin
docker pull dpage/pgadmin4 - Create coupon table in postgresql database using pgadmin
CREATE TABLE Coupon( ID SERIAL PRIMARY KEY NOT NULL, ProductName Varchar(24) NOT NULL, Description TEXT, Amount INT ); INSERT INTO Coupon (ProductName, description, amount) VALUES ('IPhone X', 'IPhone Discount', 150); INSERT INTO Coupon (ProductName, description, amount) VALUES ('Samsung 10', 'Samsung Discount', 100);
- Install the nuget package - Dapper
- Install the nuget package - Npgsql
- Create docker compose file
- Right-click the project
- Go to Add > Add container Orchestrator support
- Select Docker compose and click ok
- Select Target OS as Linux
- DockerFile will be created in the project
- Docker compose will be updated
- Execute the below command to run the docker container
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d
- Create a new project Discount.Grpc with the template ASP.NET Core gRPC.
- Change the running port and url
- Right-click on the project and go to properties.
- Go to Debug tab.
- Select Discount.API from the profile.
- Check the app url at the bottom.
- The new profile gets added in the launchsettings.json in properties folder.
- Install the nuget package - Dapper
- Install the nuget package - Npgsql
- Go to properties of the Discount.proto file
- Change the build action to Protobuf compilers
- Change gRPC stub classes to Server Only
- Open Discount.Grpc.csproj file
- Remove the below lines if present
<ItemGroup> <None Remove="Protos\discount.proto" /> </ItemGroup>
- Remove the below lines if present
- Build the project to generate the gRPC files in ~\Discount.Grpc\obj\Debug\net5.0\Protos\
- Install the nuget package - AutoMapper.Extensions.Microsoft.DependencyInjection
- Add gRPC client in Basket API
- Right click on basket api project
- Go to Add > Connected Services
- Add new service reference for gRPC
- Select the .proto file from discount grpc project
- Select client
- Create docker compose file
- Right-click the project
- Go to Add > Add container Orchestrator support
- Select Docker compose and click ok
- Select Target OS as Linux
- DockerFile will be created in the project
- Docker compose will be updated
- Execute the below command to run the docker container
docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d --build
- Create a new project Ordering.API with the template ASP.NET Core Web API.
- Change the running port and url
- Right-click on the project and go to properties.
- Go to Debug tab.
- Select Catalog.API from the profile.
- Check the app url at the bottom.
- The new profile gets added in the launchsettings.json in properties folder.
- Create a new project Ordering.Domain with the template class library c#.
- Common --> EntityBase, ValueObject
- Entities
- Create a new project Ordering.Application with the template class library c#.
- Behaviour
- Contracts
- Persistence - IAsyncRepository and other Repository interfaces
- Infrastructe - Other third party integration interfaces
- Features - Each feature folder will have
- Commands
- Queries
- Mappings
- Models
- Exceptions
- Create a new project Ordering.Infrastructure with the template class library c#.
- Install the nuget package - AutoMapper
- MediatR pipeline
Caller > Request > mediatR > Pre Processor Behaviour > Handler > post Processor Behaviour - Install the nuget package - MediatR.Extensions.Microsoft.DependencyInjection
- Install the nuget package - Microsoft.Extensions.Logging.Abstractions
- Install the nuget package - FluentValidation
- Install the nuget package - AutoMapper.Extensions.Microsoft.DependencyInjection
- Install the nuget package - FluentValidation.DependencyInjectionExtensions
- Install the nuget package - Microsoft.EntityFrameworkCore.SqlServer
- Install the nuget package - SendGrid
- Install the nuget package - Microsoft.EntityFrameworkCore.Tools
- Run the below command in ordering infrastructure project
Add-Migration InitialCreate - Create a new class project - EventBus.Messages
- Install the below nuget packages in Basket.API and ordering.API projects
- MassTransit
- MassTransit.RabbitMQ
- MassTransit.AspNetCore
- Create a new ASP.Net core empty project - ApiGateways
- Install the nuget package - Ocelot
- Install the nuget package - Ocelot.Cache.CacheManager
- Create a new project Shopping.Aggregator with the template ASP.NET Core Web API.
- MongoDB.Driver
- Microsoft.Extensions.Caching.StackExchange
- Newtonsoft.Json
- Dapper
- Npgsql
- AutoMapper.Extensions.Microsoft.DependencyInjection
- Automapper
- MediatR.Extensions.Microsoft.DependencyInjection
- Microsoft.Extensions.Logging.Abstractions
- FluentValidation
- AutoMapper.Extensions.Microsoft.DependencyInjection
- FluentValidation.DependencyInjectionExtensions
- Microsoft.EntityFrameworkCore.SqlServer
- SendGrid
- Microsoft.EntityFrameworkCore.Tools
- MassTransit
- MassTransit.RabbitMQ
- MassTransit.AspNetCore
- Ocelot
- Ocelot.Cache.CacheManager
- mongo
- mongoclient
- redis
- portainer/portainer-ce
- postgres
- dpage/pgadmin4
- mcr.microsoft.com/mssql/server:2017-latest
- rabbitmq:3-management-alpine
- https://github.com/aspnetrun
- https://github.com/aspnetrun/run-aspnetcore-microservices
- https://stackoverflow.com/questions/62441307/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2
- https://newbedev.com/how-can-i-change-the-location-of-docker-images-when-using-docker-desktop-on-wsl2-with-windows-10-home
- https://documentation.portainer.io/quickstart/
- https://www.pgadmin.org/
- https://enterprisecraftsmanship.com/posts/entity-vs-value-object-the-ultimate-list-of-differences/
- https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/implement-value-objects
- https://sendgrid.com/
- https://andrewlock.net/the-difference-between-getservice-and-getrquiredservice-in-asp-net-core/
- https://github.com/aspnetrun/run-aspnet-identityserver4
- https://ocelot.readthedocs.io/en/latest/introduction/gettingstarted.html
- https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-5.0
- https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests