This is the summary post of the series. I would recommend you to read following posts first:
1. Implementing Generic Repository and Unit of Work Pattern With Entity Framework
2. Dependency Injection in ASP.NET MVC using Autofac and CRUD operations
Patterns and Principles:
In the series, we implemented following patterns and principals:
Inversion of control and Dependency injection
You would like to read also:
YAGNI : You aren't gonna need it
General Steps after Core Implementation:
1. Create Model class
2. Create Repository class by inheriting GenericRepository class.
3. Create Service class by inheriting EntityService class.
4. Add new Controller and Views for CRUD and other operations
5. Create Test class for unit and other testing
Unit Testing:
If you are new to unit testing, see following:
1. Create Mock object of dependencies, arguments or properties.
2. Define/Implement the methods or properties of mock object which are being used in the method to be tested.
3. Call the method with Mock objects.
4. verify the result in the assert section.
Suppose you want to test a controller method then you have to mock the service layer and setup the service methods being used in the method.
Similarly, for testing service layer method, you have to mock repository layer.
Source Code:
Conclusion:
In this series, we implemented
1. a sample on Repository and Unit of Work with IoC container.
2. To keep a clean separation of concerns.
3. To prevent direct queries on top of entity framework in service or web layer.
4. All layers are easy to test.
Enjoy Architecture !!