Udemy, inc. clean architecture essencial - asp .net core com c#

Pinned

  1. 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 C…

    C# 1.6k 917

  2. A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and D…

    C# 397 138

  3. AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS, AWS CDK stands for Cloud Development Kit for IaC — Infrastructure as Code t…

    JavaScript 171 77

  4. Design Microservices Architecture with Patterns & Principles. We're going to learn how to Design Microservices Architecture with using Design Patterns, Principles and the Best Practices. You will L…

    232 227

  5. E-Commerce real world example of run-aspnetcore ASP.NET Core web application. Implemented e-commerce domain with clean architecture for ASP.NET Core reference application, demonstrating a layered a…

    SCSS 358 156

  6. DotnetCrawler is a straightforward, lightweight web crawling/scrapying library for Entity Framework Core output based on dotnet core. This library designed like other strong crawler libraries like …

    C# 137 50

Hi Friends,

In this section, we will continue from the last post and will delve inside API implementation inside clean architecture.

Udemy, inc. clean architecture essencial - asp .net core com c#

Git Link:- https://github.com/rahulsahay19/azconf-clean-architecture

Here, I have already added required nuget packages in my API project as shown below.

Here, I will adding required dependencies like Automapper, swagger, MediatR etc. This is the finished version of startup.cs file.

Now, let me go ahead and create connection string settings in App Settings. Here is the snippet for the same.

Here, I will be running on docker on port 1445. Here, I have also specified User Id and Password for the same. Now, let me go ahead and create base controller with the name ApiController itself. Here is the snippet looks like

Here, I have applied all the required things like API versioning, Route, Annotation and inherited the same with ControllerBase as well. Then, I have created Movies Controller as shown below

Here, I have first injected the Mediator. Therefore, via this and I will issue both read and write request and will do the bifurcation whether its a read query or write query. But before running that, one last thing we need to do is to update the program.cs file to seed the db. Here is the snippet for the same.

It means while starting the app, I am first seeding the db here. Having said that let’s go ahead and run the SQL in docker first with below command.

docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=Docker@1’ -p 1445:1433 -d mcr.microsoft.com/mssql/server:2019-latest

Having said that, it will look like

Udemy, inc. clean architecture essencial - asp .net core com c#

This SHA value is the representation of that container started successfully. You can verify the same using docker ps command as shown below.

Udemy, inc. clean architecture essencial - asp .net core com c#

With this in place, now I can go ahead and run my app, it will open like shown below

Udemy, inc. clean architecture essencial - asp .net core com c#

At the same time, I can now open sql server instance like shown below.

Udemy, inc. clean architecture essencial - asp .net core com c#

Here, server name will go like localhost,1445 and then provide User ID and Passwordas provided in the app settings and while running the SQL conatiner. Here, you can see that database is successfully seeded.

Udemy, inc. clean architecture essencial - asp .net core com c#

Now, let’s go ahead and try running the query and let’s put breakpoint in the visual studio to see the workflow.

Udemy, inc. clean architecture essencial - asp .net core com c#

Then, in Visual Studio, it will come like this

Udemy, inc. clean architecture essencial - asp .net core com c#

Udemy, inc. clean architecture essencial - asp .net core com c#

Then, mediator will process the query like shown below.

Udemy, inc. clean architecture essencial - asp .net core com c#

Udemy, inc. clean architecture essencial - asp .net core com c#

Having said that, here it produced the final result like this.

Udemy, inc. clean architecture essencial - asp .net core com c#

Similarly, it goes for command handler as well means for inserting the record.

Udemy, inc. clean architecture essencial - asp .net core com c#

Udemy, inc. clean architecture essencial - asp .net core com c#

This will land in command handler

Udemy, inc. clean architecture essencial - asp .net core com c#

And, upon execution, this will post one new record in the db like shown below.

Udemy, inc. clean architecture essencial - asp .net core com c#

Having said that, we have concluded this Clean Architecture session. I hope you would have liked this article. You can refer the code as mentioned in the git link.

Git Link:- https://github.com/rahulsahay19/azconf-clean-architecture

With this I would like to wrap this session here. Thanks for joining me.

Thanks,
Rahul Sahay
Happy Coding