Skip to content

Generic Repository and UnitOfWork Pattern implementation with base classes for Entity Framework

Notifications You must be signed in to change notification settings

jiehanlin/RepositoryT.EntityFramework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RepositoryT.EntityFramework

Generic Repository and Pattern UnitOfWork implementation with base classes.

sample repository

 public interface IUserRepository: IRepository <User> 
 {
 }

 public class UserRepository: EntityRepository <User, SampleDataContext> , IUserRepository 
 {
  public UserRepository(IServiceLocator serviceLocator): base(serviceLocator) {

  }
 }

sample service

  public interface IUserService
  {
    int AddUser(User user);
    IEnumerable<User> GetAll();
  }
  
  public class UserService : IUserService
  {
   private readonly IUnitOfWork _unitOfWork;
   private readonly IUserRepository _userRepository;

   public UserService(IUnitOfWork unitOfWork, IUserRepository userRepository)
   {
     _unitOfWork = unitOfWork;
     _userRepository = userRepository;
   }

    public int AddUser(User user)
    {
      _userRepository.Add(user);
      _unitOfWork.Commit();
      return user.Id;
    }

    public IEnumerable<User> GetAll()
    {
      return _userRepository.GetAll();
    }
  }

To see sample autofac registrations

NOTE : To see more samples please look at code samples.

About

Generic Repository and UnitOfWork Pattern implementation with base classes for Entity Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%