Verwenden von UnitOfWork und Repository Pattern mit Entity Framework

Ich werde Repository und UnitOfwork in meiner Datenzugriffsebene verwenden, um dies zu tun. Schauen Sie sich einen Kontaktaggregatstamm an

 public interface IAggregateRoot
    {
    }

Dies ist meine generische Repository-Schnittstelle:

 public interface IRepository<T>
        {
            IEnumerable<T> GetAll();
            T FindBy(params Object[] keyValues);
            void Add(T entity);
            void Update(T entity);
            void Delete(T entity);

        }

und meine POCO Contact Klasse in Model

 public class Contact :IAggregateRoot
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public string Email { get; set; }
            public string Title { get; set; }
            public string Body { get; set; }
            public DateTime CreationTime { get; set; }
        }

und das mein IContactRepository das von IRepository erbt und vielleicht auch eine eigene Methode hat

 public interface IContactRepository : IRepository<Contact>
        {
        }

Jetzt habe ich in IUitOfWork und UnitOfwork so gemacht

public interface IUnitOfWork 
    {
        IRepository<Contact> ContactRepository { get; }
    }

public class UnitOfWork : IUnitOfWork
    {
        private readonly StatosContext _statosContext = new StatosContext();
        private IRepository<Contact> _contactUsRepository;

 public IRepository<Contact> ContactRepository
        {
            get { return _contactUsRepository ?? (_contactUsRepository = new Repository<Contact>(_statosContext)); }
        }
}

auch über mein Repository

public class Repository<T> : IRepository<T> where T : class, IAggregateRoot
    {
       //implementing methods 
    }

Ich kann alle CRUD-Operationen ausführen, indem ich mit UnitOfwork in Service auf Repositories zugreife. Beispiel:

_unitOfWork.ContactRepository.Add(contact);
            _unitOfWork.SaveChanges();

aber ich möchte das gerne machen

_

ContactRepository.Add(contact);
            _unitOfWork.SaveChanges();

(CRUD und generische Methode über _ContactRepository No von _unitOfWork.ContactRepository abrufen) Da ich die ContactRepository-Methode für bestimmte Abfragen verwenden möchte, hilft jemand bitte?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage