Shopping Cart Application Part-07 (Repository contracts)

By | April 10, 2015

@In my previous post I discussed about Product Catalog.
@. Now I will create Repository interfaces.
@. These interfaces actually act like contracts with their implementations.
@. They will also specify what will must implement by a concrete class (that implements the interface)
@. In our Product catalog we defined three entities as Aggregate Root i.e. inherits three entities by IAggregateRoot interface.
@. Those three classes are:

@@. Category
@@. ProductTitle
@@. Product

@. So we’ll define three Repositories for above three entities.
@. Add three interfaces inside Shoppingcart.Repositories.Contracts and named them:

@@. ICategoryRepository
@@. IProductRepository
@@. IProductTitleRepository

@. Though we’re not going to Save, Update, Delete records for above entities so we’ll inherit all that repositories by IReadonlyRepository (that’s defined inside Domain folder of Infrastructure layer) as follows:

public interface ICategoryRepository : IReadOnlyRepository
{

}
public interface IProductTitleRepository:IReadOnlyRepository
{

}
public interface IProductRepository : IReadOnlyRepository
{

}

Note:
We could use our generic repository for above all domain models. So why we created individual repository contract for each domain model? The answer is “in some situation me may need to add one or more extra method for a specific domain model. So we have to modify generic repository in order to add those methods which is completely the violations of Open Closed Principle (OCP). Also if we continue the adding of methods inside generic repository once it will be heavy which violates the rule of Interface Segregation Principle (ISP) which says us that our interfaces should be thin and simple. So in order to avoid those situation we segregated our repositories for each domain model. Now we will be easily add one or more methods for individual repository where required and it wouldn’t affect our generic repository and also our generic repositories will remain thin and simple.

One can download entire source from here

499 Total Views 1 Views Today
Md. Mojammel Haque

CSM, CSPO, CSD, CSP-SM, CSP-PO (ScrumAlliance.org)
Certification Profile Link-
https://www.scrumalliance.org/community/profile/mhaque13

Currently working as Lead Team (Application Architecture) at Raven Systems Ltd. Passion for software development especially agile practices such as TDD with in depth knowledge of Object Oriented Programming, SOLID Principles, Gang of Four Design Patterns, Some Enterprise Application Architectural Patterns. Over 8 years of software development experience ASP.NET. Has the ability to understand and transform complex business requirements into software ensuring applications are delivered on time. Also experience in non Microsoft .NET technologies such as Dapper.Net, Git, Structure Map & Angular, Bootstrap, HTML-5, CSS-3 etc.

Category: Asp.net MVC Learn by doing - ASP.Net MVC Tags: , , ,
Md. Mojammel Haque

About Md. Mojammel Haque

CSM, CSPO, CSD, CSP-SM, CSP-PO (ScrumAlliance.org) Certification Profile Link- https://www.scrumalliance.org/community/profile/mhaque13 Currently working as Lead Team (Application Architecture) at Raven Systems Ltd. Passion for software development especially agile practices such as TDD with in depth knowledge of Object Oriented Programming, SOLID Principles, Gang of Four Design Patterns, Some Enterprise Application Architectural Patterns. Over 8 years of software development experience ASP.NET. Has the ability to understand and transform complex business requirements into software ensuring applications are delivered on time. Also experience in non Microsoft .NET technologies such as Dapper.Net, Git, Structure Map & Angular, Bootstrap, HTML-5, CSS-3 etc.

Leave a Reply

Your email address will not be published. Required fields are marked *