Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the way i usually do it in my implementations.</p> <p>A generic interface, IEntityRepository which defines your basic CRUD structure. In my implementations i define the following members:</p> <ol> <li>Insert</li> <li>Update</li> <li>Delete</li> <li>Get</li> <li>GetPaged</li> <li>GetAll</li> <li>Find (This one is using a predicate builder to build the where clause)</li> </ol> <p>I create another interface IMyentityRepository which inherits IEntityRepository. This allows me to add any entity-specific members and still be able to use DI when i need to. I then create my sealed class MyentityRepository which inherits IMyentityRepository and implements all members. </p> <p>When you use Dependency Injection you can register your interface (IMyentityRepository) for concrete type of MyentityRepository.</p> <p>In my case, i wasn't actually done. I created a service layer on top of the repository to encapsulate it and expose it in a more general way. For instance, say you want to create an account for your user which may involve more work than simply creating a database record. In your service, you'd have a member called CreateUser() which may call multiple repository members in its implementation. My service layer is built in the same was as my repository layer. I have IEntityService for common CRUD members, IMyentityService for entity-specific members and MyentityService for implementation. MyentityService class would require an instance of IMyentityService (You can inject it with your IoC framework of choice) Your service layer may also do validation and any business logic. I do validation in controllers. Well, technically, i invoke it my controllers and get the result that i can then write to ModelState. </p> <p>Hope that helped a little.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload