Getting Started with Clean Architecture using ASP.Net Core – Part 2

Hi Friends,

In this section, we are going to extend our last example from where we left. In the last section, what we have done, we have created Core layer. Now, let’s go ahead and implement Infrastructure Layer.

Source:- https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

Now, in Infrastructure layer, let’s implement these. Let’s first create two folders Data and Repositories first of all. Create one more folder Base inside Repositories folder. Now, let’s go ahead and create MovieContext class in Data folder. Here, we will be implementing EntityFrameworkCore DbContext. This, we have been doing for a while, hence not explaining these infrastructure code here. This is pretty self explanatory.

Now, let’s go ahead and create MovieContextSeeed class for seeding data.

Then, in Repositories –> Base folder, I will create Repository class like shown below. Here, I have implemented the interface for generic CRUD.

Now, for custom operation, I will be creating another class MovieRepository in Repositories folder. It will look like as shown below.

So, here I am implementing Repository and IMovieRepository as well. This means I will have access to generic and custom code as well.

With this change, now my Infrastructure layer looks like

With this I would like to wrap this here. In the next article, we will discuss API layer. Till then stay tuned and Happy Coding.

Thanks,
Rahul Sahay
Happy Coding

337 total views, 1 views today