-
Notifications
You must be signed in to change notification settings - Fork 2
How to create Repository
marektihkan edited this page Sep 13, 2010
·
2 revisions
- Create repository interface to
Core.(BoundedContext).Services.Repositories
namespace - Create repository class to
Services.Repositories
namespace - Inherit this class from
Arc.Infrastructure.Data.BaseRepository<TEntity>
- Create default constructor for this class with
IRepository<TEntity>
public PersonRepository(IRepository<Person> repository) : base(repository) {}
- Use InnerRepository property to create queries, save, delete etc
- Register repository to Service Locator if needed (use conventions for less configuration)
- Repository should be registered to Service Locator
namespace ExampleSolution.Core.Parties.Services.Repositories
{
public interface IExampleEntityRepository
{
Person GetPersonById(int id);
IList<Person> GetAllPersons();
long GetPersonsCount();
void Save(Person entity);
void Delete(Person entity);
}
}
namespace ExampleSolution.Services.Repositories
{
public class PersonRepository : BaseRepository<Person>, IPersonRepository
{
public PersonRepository(IRepository<Person> repository) : base(repository) {}
public Person GetPerson(int id)
{
return InnerRepository.GetEntityById(id);
}
public IList<Person> GetAllPersons()
{
return InnerRepository.GetAllEntities<Person>();
}
public long GetPersonsCount()
{
return InnerRepository.Count(InnerRepository.CreateCriteria<Person>());
}
public void Save(Person entity)
{
InnerRepository.Save(entity);
}
public void Delete(Person entity)
{
InnerRepository.Delete(entity);
}
}
}