On methane there is an example of onion architecture. There was a question about this architecture. There, in the example, the infrastructure.Business layer is created and links to domain.core and Services.Interfaces are connected to this project. And is it considered normal to connect to the infrastructure.Business layer, the Infrastructure.Data layer, and that the business infrastructure have access to the context of the application data and, accordingly, the unit of work class, i.e. work directly with the base? Or is it a bad tone for this architecture?
This is the structure of my application at the moment.
Here is a specific project responsible for receiving data from the database.
UnitOfWork class:
public class UnitOfWork : IDisposable { private Context db = new Context(); private ClientRepository clientRepository; public ClientRepository Clients { get { if (clientRepository == null) clientRepository = new ClientRepository(db); return clientRepository; } } public void Save() { db.SaveChanges(); } private bool disposed = false; public virtual void Dispose(bool disposing) { if (!disposed) db.Dispose(); disposed = true; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } } Client repository:
public class ClientRepository : IRepository<Client> { private Context db; public ClientRepository(Context context) { db = context; } public IEnumerable<Client> GetAll() { return db.Clients.ToList(); } public IEnumerable<dynamic> GetFieldsValue(Func<Client, Boolean> predWhere, Func<Client, dynamic> predSelect) { return db.Clients.Where(predWhere).Select(predSelect).ToList(); } public Client Get(int id) { return db.Clients.Find(id); } public void Create(Client client) { db.Clients.Add(client); } public void Update(Client client) { db.Entry(client).State = EntityState.Modified; } public void Delete(int id) { Client client = db.Clients.Find(id); if (client != null) db.Clients.Remove(client); } } Client domain model from the Domain.Core project:
public class Client { public int Id { get; set; } [Required] [Display(Name = "Фамилия")] public string CSurname { get; set; } [Required] [Display(Name = "Имя")] public string CName { get; set; } [Required] [Display(Name = "Отчество")] public string CPatronymic { get; set; } [Required] [Display(Name = "Логин")] public string Login { get; set; } [Required] [Display(Name = "Пароль")] public string Password { get; set; } [Required] [Display(Name = "E-meil")] public string Email { get; set; } public virtual ICollection<Order> Orders { get; set; } public Client() { Orders = new List<Order>(); } } Repository Interface:
public interface IRepository<T> where T : class { IEnumerable<T> GetAll(); T Get(int id); IEnumerable<dynamic> GetFieldsValue(Func<T, Boolean> predWhere, Func<T, dynamic> predSelect); void Create(T item); void Update(T item); void Delete(int id); } 
