Introduction
If you are planning to use Repository pattern in your project, then 'SharpRepoGen' is definitely going to be a best help for you. Using this you may avoid creating the similar pattern Repositry Classes and its interfaces. Using this tool easily you can generate your repositry class and interface. Code is generated with the help of xml template, so very easily you may change the template to create your source code as per your requirement.
Section Tools, Design Pattern
Background
Repository Design pattern now a days has become very popular. This tool helps to implement the same without much effort.
Using the Code
Tool does most of the things for you, you simply need to provide your database credentials for which you want to create CRUD.
You simply need modify Template xml (basic setting done) to achieve your own naming conventions and coding standards.
Download the demo project and unzip the downloaded file.
- You will see SharpRepoGen.exe file, double click it to Run.
- Enter your database credentials and hit login.
- You will be redirected to a new screen where, you will see your database tables on the left.
- Select your tables for which you want to generate the repository classes. Use Ctrl + A and Ctrl + N to Select All/ Select None.
- Hit F5 to generate the repository classes.
- Select appropriate radio button Interface/ Repository Classes to see the files generated. You may click on file name to preview the same.
- Hit Ctrl + T to modify the template if you want to modify the template.
As discussed earlier, that source code is generated with the help of xmls, so that we can modify it easily. (Template.xml). So this option enables you to do the changes as per your need e.g. Changing namespace or any naming convention.
Tool generates two objects, one is interface and another is its implementing class. Suppose, your table name is User, then it generate objects i.e. classes and interface with name IUserRepositry
and UserRepository
. Also, it generate CRUD functions as GetUsers
, GetUserById
, InsertUser
, DeleteUser
and UpdateUser
. If you want any changes in these emails, you may change corresponding template (interface/ repository), highlighted below with yellow color.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Legalxgen.Entity.DataAccess;
namespace Legalxgen.DataAccess.Repository
!cur_brak_op#
public interface I{0}Repository
!cur_brak_op#
IEnumerable<{0}> Get{0}s();
{0} Get{0}ByID(int {1}Id);
void Insert{0}({0} {1});
void Delete{0}(int {1}Id);
void Update{0}({0} {1});
void Save();
!cur_brak_cl#
!cur_brak_cl#
Points of Interest
On the development point of view its pretty straight forward, but on the usage side its quite waste, it reduces your effort to create these interfaces and classes.