I'm digging on how to structure projects and so I stumble into Onion Architecture. As to how I understand it, its more on a domain-centered-focus architecture instead of a database-driven type.
I'm looking for some github projects to study and learn more about the architecture, so I found this one https://github.com/chetanvihite/OnionArchitecture.Sample
I'm having hard time understanding:
namespace Domain.Interfaces
{
public interface IUserRepository
{
IEnumerable<User> GetUsers();
}
}
namespace Services.Interfaces
{
public interface IUserService
{
IEnumerable<User> GetUsers();
}
}
namespace Services
{
public class UserService : IUserService
{
private readonly IUserRepository _repository;
public UserService(IUserRepository repository)
{
_repository = repository;
}
public IEnumerable<User> GetUsers()
{
return _repository.GetUsers();
}
}
}
How he use it is by constructor injection.
private readonly IUserService _service;
public HomeController(IUserService service)
{
_service = service;
}
Do you always expose a service such as
IUserService
to an app that consumes it? But I noticed,IUserRepository
has the same methods toIUserService
?If you say Infrastructure concerns, does it mean or does it involve database? Or not necessarily? if not, what are examples of infrastructure concerns?
P.S. As I'm learning onion architecture, it always, if not always, at least it mention about DDD. So I guess, I'll be learning DDD also :)