.NET Core Web API Microservice with SQL Server Entity Framework Core

  Рет қаралды 42,043

Coding Droplets

Coding Droplets

Күн бұрын

In this video we explains how to create a .NET Core Web API Microservice with SQL Server Entity Framework Core.
Microservice Architecture Playlist: Microservices Tutorial Playlist Link: • What are Microservices...
The Microservice Architecture has become hugely popular in recent years. Experts predict that all New Apps Will Feature Microservice Architectures that improve the ability to design, debug, update, and leverage third-party code. Microservice architecture will continue to help businesses reduce downtime, optimize resources, and decrease infrastructure costs.
This video is also an ASP.Net core web API tutorial for beginners as we have completely included the ASP.Net Core API development. It can also be considered as a Entity Framework Core Tutorial.
In this .NET Docker tutorial, you'll learn how to manage more than one container and communicate between them when using Container Tools in Visual Studio. Managing multiple containers requires container orchestration and requires an orchestrator such as Docker Compose, Kubernetes, or Service Fabric. Here, we'll use Docker Compose. Docker Compose is great for local debugging and testing in the course of the development cycle. This is a very important video as it covers a major part of Docker .Net Core Microservices.
Visual Studio provides the options to easily develop applications with Docker Support, Debug with Docker [Docker .Net Core Debug], and Deploy the Docker Container [Deploy .Net Core to Docker].
We are using the Official container image for Microsoft SQL Server on Linux for Docker Engine [SQL Server Docker]. We'll use this docker image for creating a container for SQL Server Database. Then the .Net Core application container can connect to the database container for read-write operations.
We are making use of Entity Framework Core (Entity Framework Core Tutorial) for SQL Server Database operations.
Entity Framework Core is the new version of Entity Framework after EF 6.x. It is open-source, lightweight, extensible and a cross-platform version of Entity Framework data access technology. Entity Framework is an Object/Relational Mapping (O/RM) framework. It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in the database. EF Core is intended to be used with .NET Core applications. However, it can also be used with standard .NET 4.5+ framework based applications.
Visual Studio provides a consistent way to develop Docker containers and validate your application locally. You can run and debug your apps in Linux or Windows containers running on your local Windows desktop with Docker installed, and you don't have to restart the container each time you make a code change.
You can view what's going on inside the containers that host your app by using the Containers window. If you're used to using the command prompt to run Docker commands to view and diagnose what's going on with your containers, this window provides a more convenient way to monitor your containers without leaving the Visual Studio IDE.
What is Docker Compose?
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Docker .Net Core:
.NET Core can easily run in a Docker container. Containers provide a lightweight way to isolate your application from the rest of the host system, sharing just the kernel, and using resources given to your application. Learn how to use docker for .Net Core and deploy .Net Core to Docker.
.NET Core images
Official .NET Core Docker images are published to the Microsoft Container Registry (MCR) and are discoverable at the Microsoft .NET Core Docker Hub repository. Each repository contains images for different combinations of the .NET (SDK or Runtime) and OS that you can use.
Microsoft provides images that are tailored for specific scenarios. For example, the ASP.NET Core repository provides images that are built for running ASP.NET Core apps in production.
The tools included in Visual Studio for developing with Docker containers [.Net Core Docker Container] are easy to use, and greatly simplify building, debugging, and deployment for containerized applications. You can work with a container for a single project, or use container orchestration with Docker Compose or Service Fabric to work with multiple services in containers.
Docker support in Visual Studio:
Docker support is available for ASP.NET projects, ASP.NET Core projects, and .NET Core and .NET Framework console projects.
Video Chapters:
0:00 - Video Summary
1:08 - Project Setup
3:38 - ASP.Net Core Web API Development
9:15 - API Testing with Postman
13:49 - Container Orchestration Support

Пікірлер: 45
@CodingDroplets
@CodingDroplets 2 жыл бұрын
⭐ Join Us on Patreon: www.patreon.com/CodingDroplets Microservices Tutorial Playlist Link: kzfaq.info/get/bejne/nbZ5oc59qMzFnHk.html
@guillermomazzari4983
@guillermomazzari4983 Жыл бұрын
Please ignore this question, I managed to solve it out, I had an indentation issue, I didn't know yaml files work similar to python, regarding indentation, thanks!
@SiegfriedFarnonMRCVS
@SiegfriedFarnonMRCVS Жыл бұрын
Excellent. Pitched perfectly. I am an experienced developer. I don't need a lot of obvious explanations and you have got this just right. There are other videos which would take 90 minutes to explain what you just showed in 20. Good stuff. Keep it up. Subscribed and liked
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for sharing your thoughts and subscribing. Glad to know you liked it.
@Yhau1989
@Yhau1989 Жыл бұрын
Nice project
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for your kind comment! We're delighted that you liked it.
@engineersINnight
@engineersINnight 6 ай бұрын
Nice Demo
@CodingDroplets
@CodingDroplets 6 ай бұрын
Thanks!
@vijayarajan-bt5fk
@vijayarajan-bt5fk Ай бұрын
Very fast . But Much Clear Thanks
@CodingDroplets
@CodingDroplets Ай бұрын
Thank you for your feedback! I'm glad you found the tutorial clear and helpful.
@akashgupta2366
@akashgupta2366 2 жыл бұрын
Great tutorial to learn from ground level, you please share Git repo.
@CodingDroplets
@CodingDroplets 2 жыл бұрын
Thank You! Below is the Github repo url: github.com/codingdroplets/DemoMicroserviceSolution
@TheLilRussia
@TheLilRussia Жыл бұрын
Great Video! I have one question though. Is it safe to use the sa user for every microservice, or would you create a new db login and user for each microservice?
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for watching my video and leaving such a thoughtful comment! I appreciate your engagement and am glad to hear that you found the video helpful. Regarding your question, it's generally not recommended to use the SA user for every microservice, as it can create security risks. Ideally, you should create a new database login and user for each microservice, with limited permissions based on what that service needs to do in the database. This approach helps to limit potential security vulnerabilities and makes it easier to manage access and permissions for each service separately. It also helps to ensure that each microservice only has access to the data it needs to function, reducing the risk of accidental or malicious data leaks. Of course, the specifics of how you set up database access and user permissions will depend on your particular application and security requirements, but I hope this provides some helpful guidance. Thanks again for your question and I hope you continue to find value in my content!
@TheLilRussia
@TheLilRussia Жыл бұрын
@@CodingDroplets Wow, thank you for the detailed answer. Have blessed day.
@CodingDroplets
@CodingDroplets Жыл бұрын
Great to hear that! Your kind words mean a lot to me, and I appreciate your support. Have a blessed day too!
@YakubuAzure
@YakubuAzure Жыл бұрын
Hi, great tutorial but I encountered this error when I cloned your repo " Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user 'sa'. at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) " I initially followed your tutorial & did the same thing & still encountered that error. Can you assist?
@CodingDroplets
@CodingDroplets Жыл бұрын
The application is unable to connect to SQL Server. Please check your connection string. The source code is available in the below github URL. Please verify your code. github.com/codingdroplets/DemoMicroserviceSolution
@crashgames58
@crashgames58 Жыл бұрын
Hello. Help pls. Where I can find a correct user ID? I have a problem in connection string, so I want you to desribe what every property means.
@CodingDroplets
@CodingDroplets Жыл бұрын
You can find the connection string in Program.cs class. We are reading the Db Host, Db Name and Password from environment variables. In this video, we've hardcoded sa user id. You can include that as well in environment variables in the same way if needed.
@naveenranjitkar8937
@naveenranjitkar8937 Жыл бұрын
Good Video, but I can't connect Database when following your codes. Would you help me?
@CodingDroplets
@CodingDroplets Жыл бұрын
Thank you for your feedback and I'm sorry to hear that you're having trouble connecting to the database, I would be happy to assist you, can you please provide more details about the issue you're facing? Also, I wanted to let you know that the demo project shown in the video is available in a GitHub repository at github.com/codingdroplets/DemoMicroserviceSolution, so you can refer to that as a reference to see if there are any differences in your code.
@hermanpranoto3772
@hermanpranoto3772 11 ай бұрын
when creating docker. when they ask target OS. should i choose windows because im using windows or i still choose linux anyway?
@hermanpranoto3772
@hermanpranoto3772 11 ай бұрын
ok next question. after installing docker. i cant login in ssms with localhost.8001 is something i missed?
@hermanpranoto3772
@hermanpranoto3772 11 ай бұрын
now i have this error System.Exception: Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started. when try connect to 8002 from postman. ?
@user-mb3cz8nb9i
@user-mb3cz8nb9i 6 ай бұрын
@@hermanpranoto3772 Where you able to solve this? I facing the same issue, but my host system is mac
@ErikKillmonger185
@ErikKillmonger185 4 ай бұрын
Hi, I also got the target OS issue. Have you resolved it and how to do .Thanks
@abdulmussavir4627
@abdulmussavir4627 Жыл бұрын
Hello Bro When I run docker-Compose. So I have received this type of error: The "PrepareForLaunch" task failed unexpectedly. Please can you solve this query
@CodingDroplets
@CodingDroplets Жыл бұрын
The error message "The 'PrepareForLaunch' task failed unexpectedly" can occur due to a variety of reasons, so it's difficult to provide a definitive solution without more information about the specific error. However, here are some general troubleshooting steps that you can follow to help resolve the issue: Check the logs: The first step is to check the logs for the Docker containers that failed to start. You can use the docker-compose logs command to view the logs for all the containers in the compose file. Look for any error messages or exceptions that may provide more information about the cause of the error. Check the Docker Compose file: Make sure that the Docker Compose file is correctly configured and that all the necessary services and dependencies are defined. Check that the service names and container names match in the Compose file and in any other configuration files. Check the environment variables: Make sure that any environment variables required by the application or the containers are correctly defined in the Docker Compose file or in any other configuration files. Check the networking: Check that the containers are correctly configured to communicate with each other. Make sure that the ports are correctly exposed and that the networking is configured to allow communication between the containers. Check the Docker installation: Make sure that Docker is correctly installed and configured on the host system. Check that the Docker daemon is running and that the Docker CLI is correctly configured to communicate with the daemon. I hope this helps you troubleshoot the issue and resolve the error. If you have any further queries or concerns, please feel free to let me know!
@pks001
@pks001 5 ай бұрын
Hi, If we have multiple WebApis (eg: 2 Api), then should we create 2 Docker container for each Api? please confirm
@CodingDroplets
@CodingDroplets 5 ай бұрын
Yes, typically each API Application would have its own Docker container. This approach allows for better isolation, scalability, and management of each API Application individually. It also follows the microservices architecture pattern, where each service is encapsulated within its own container.
@pks001
@pks001 5 ай бұрын
@@CodingDroplets Thanks. It's helpful
@CodingDroplets
@CodingDroplets 5 ай бұрын
You are most welcome!
@antoniooliveira4265
@antoniooliveira4265 2 жыл бұрын
when will you post the sequel?
@CodingDroplets
@CodingDroplets 2 жыл бұрын
Working on the next video now. Will be uploading within 2-3 days.
@antoniooliveira4265
@antoniooliveira4265 2 жыл бұрын
@@CodingDroplets Thanks! I really enjoyed the videos.
@CodingDroplets
@CodingDroplets 2 жыл бұрын
You are welcome. Thanks a lot for sharing your thoughts.
@Zizzy7
@Zizzy7 Ай бұрын
This wasn't really helpful as it doesn't seem like you are explaining the micro concept. Help me understand what the correct concept of microservices are please. First create 2 Api's.. each with its own container. Then: 1. Each Api to have it's own DB and the APIs can then communicate with each other to manage databases. This means each API can use EFCore to build the DBs code first. 2. Both Api's communicate with the same DB. Which Api will then manage the DB code first generation? To me this then breaks the concept of microservices as the 2 APIs cannot live in isolation.. the one is always dependent on the other? So my question is.. Should each Api then have it's OWN db in order for it to be a microservice? If not, and you use Code First, it feels like everything gets very messy.
@CodingDroplets
@CodingDroplets Ай бұрын
In a microservices architecture, each service should indeed be autonomous and independently deployable. So it is better to have separate databases for each services. If the APIs communicate with the same database, can break the microservices principles by creating dependencies between services which makes them harder to manage and evolve independently.
@user-oc9oh2ko2p
@user-oc9oh2ko2p Жыл бұрын
Could you please suggest me to fix this issue. fail: Microsoft.EntityFrameworkCore.Database.Connection[20004] An error occurred using the connection to database 'master' on server 'customerdb'. A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught) fail: Microsoft.EntityFrameworkCore.Database.Connection[20004] An error occurred using the connection to database 'dms_customer' on server 'customerdb'. fail: Microsoft.EntityFrameworkCore.Update[10000] An exception occurred in the database while saving changes for context type 'CustomerWebApi.CustomerDbContext'. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.Security.Authentication.AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
@CodingDroplets
@CodingDroplets Жыл бұрын
Check this: stackoverflow.com/questions/3270199/a-connection-was-successfully-established-with-the-server-but-then-an-error-occ
.Net Core MySQL Microservice - Entity Framework Core MySQL
19:11
Coding Droplets
Рет қаралды 14 М.
ASP.Net Core API Gateway - Ocelot API Microservice
21:04
Coding Droplets
Рет қаралды 40 М.
Slow motion boy #shorts by Tsuriki Show
00:14
Tsuriki Show
Рет қаралды 10 МЛН
My microservices architecture based .NET project at high level
11:59
Interview Happy
Рет қаралды 32 М.
ASP.NET Core Crash Course - C# App in One Hour
1:00:44
freeCodeCamp.org
Рет қаралды 1,5 МЛН
“.NET 9 Is Killing MediatR, MassTransit & Wolverine!”
11:59
Nick Chapsas
Рет қаралды 82 М.
Deploy a .NET Core API with Docker (Step-by-Step)
36:17
Les Jackson
Рет қаралды 256 М.
Microservices Explained in 5 Minutes
5:17
5 Minutes or Less
Рет қаралды 721 М.
Serilog 🚀 Logging in .NET 7 Made Simple & Fun
16:23
Patrick God
Рет қаралды 42 М.