- Create a class library for CleanMovie.Domain and Name the solution CleanMovie
- What is a domain?
- Things you do with/without having a software for a movie rental system, you are going to walk into the store and ask-" What are the movies you have?" They might show you a book that has a list of movies kept in the store. Once you choose, they are going to take some details of you and give you the movie. Here the domains are-> movie, customer details etc.
- Add a domain class named "Movie" into the project
- Create another class library named "CleanMovie.Applicaton"
- What's for Application -> for business logics
- Add project reference of domain into application
- Add a new interface named "IMovieRepository" and add the methods you are going to use to fetch from the repository
- Add a new interface named "IMovieService" and this is going to be the use case for the domain movie
- Add a new class named "MovieService" and implement the methods from "IMovieService" and use IMovieRepository as an dependency injection
- Add a new project named "CleanMovie.Infrastructure"
-
Infrastructure is going to do the actual operations like
- talking to database
- talking to another api
- talking to system clock
- talking to file system
- anything external to your domain
-
Domain does not depend on anything
-
Application depends on Domain, domain only talks to application
-
Infrastructure depends on Application
-
Presentation depends on Application layer
-
- Add Application project referenct to CleanMovie.Infrastructure project
- Add new class named "MovieRepository" and implement IMovieRepository from application project
- Add presentation layer which is webAPI project in the same directory
- Add Application project reference to the web api project
- Add controller named "MoviesController.cs" and add api method for getting movies using service from application
- Add dependency injection in the program for IMovieServie
- Add dependency injection in the program for IMovieRepository(for that we have to add Infrastructure project reference to the presentation layer as IMovieRepository is not defined which one to implement)
- Add nuget package "EntityFrameworkCore", "EntityFrameworkCore.Design", "EntityFrameworkCore.Tools" "EntityFrameworkCore.SqlServer" into infrastructure
- Add CreateMovie method into IMovieRepository
- Implement the method CreateMovie with noImplementation in MovieRepository
- Add CreateMovie method into IMovieService
- Implement the method CreateMovie with noImplementation in MovieService
- Add MovieDbContext class into Infrastructure and inherit DbContext and add Entity Movie
- Add constructor and inject MovieDbContext into MovieRepository class
- Rewrite the CreateMovie and GetAllMovies method with MovieDbContext and remove the static movie list
- Rewrite the CreateMovie method with the help of IMovieRepository object in MovieService class
- Add post api method in MoviesController.cs
- Add ConnectionStrings in appsettings.json in the CleanMovie.API
- Register Configurationmanager and add database service in the program file in the CleanMovie.API
- Add nuget package "EntityFrameworkCore.Tools" into API project
- Register the DbContext into services into program file
- Open Package manager Console And write command for adding migration
- add-migration InitialMigration // for vs
- dotnet ef migrations add InitialMigration // for vscode
- then update the database using this command
- dotnet ef database update
- Add a class named class "Member" in cleanMovie.Api
- Add a class "Rental" in CleanMovie.API
- Modify the class "Movie"
- Modifying this class is going to make problem on migrations, so I deleted the db and migration folder for not having the problem
- Add a class named "MovieRental" in CleanMovie.API
- Go to MovieDbContext in the Infrastructure and add other Entities and add the overRide method to maintain the properties like primaryKey, foreignKey, decimals etc
- now add the migrations
- dotnet ef migrations add AddedMoviesRentalMembers
- dotnet ef database update -- this is going to make problem as there was already Movie entity in the db, so I deleted the migration folder and deleted the db and added the initial migration and update the db for shortcut resolve
- dotnet ef migrations add InitialMigration
- dotnet ef database update
- Reference: https://www.youtube.com/watch?v=KeTi_x8_4ao&list=PLBapd_vePld_986VHC2UbcPY4Q2j9-lpT&index=3
dotnet ef migrations add MigrationName dotnet ef database update dotnet ef migrations remove