I'm digging in on how to structure projects and so I stumbled upon Onion Architecture. As far as I understand it, it's more of 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 a 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 uses 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 asIUserService
?If you say Infrastructure concerns, does it mean or does it involve a database? Or not necessarily? If not, what are examples of infrastructure concerns?
- Do you have any recommendation on free projects/github projects that I can download to learn or study further about onion architecture? I understand better on examples
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 :)