This video is available to students only

Implementing Specification Methods

In this lesson, we're going to implement the Specification methods

We have just created two more methods that take the specification. It's now time to implement them in our actual Generic Repository. Let's open Generic Repository and use quick fix to implement interface. This will add two of our new methods and will get rid of the error.

First thing we need to do inside our Generic Repository is to create a method which will let us apply these specifications, so let's create a private method which will return an IQueryable of generic type T; we can call it ApplySpec. It needs an ISpecification as a parameter, so we can write ISpecification of type T; let's call it spec again. Import IQueryable from System.Linq.

Now let's write our method. If you remember, we have created GetQuery method inside Specification Evaluator class; let's use it here. This will take IQueryable of type T as the first parameter and ISpecification as the second one. We want to make our entity queryable. For example, if we go to the course repository, we are making Course Entity queryable, so we need to pass the entity as our first parameter. Since we are inside Generic repository, we want to make it dynamic, so what we can do is write \_context.Set T() and we will make it queryable by writing as queryable. In the second parameter, we can simply pass the spec.

Start a new discussion. All notification go to the author.