Created
November 21, 2019 00:03
-
-
Save jgabrielfreitas/ad108ea3ecb5a379ee6d27bc47820b0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IRepository<T> | |
| { | |
| Task Insert(T entity); | |
| Task<T> Get(T Id); | |
| Task Update(T entity); | |
| Task Delete(T entity); | |
| } | |
| public interface IUserRepository : IRepository<User> { | |
| } | |
| public class UserRepository : IRepository { | |
| public async Task Insert(User entity) { | |
| // logic | |
| } | |
| public async Task<User> Get(Guid Id){ | |
| // logic | |
| } | |
| public async Task Update(User entity) { | |
| // logic | |
| } | |
| public async Task Delete(User entity) { | |
| // logic | |
| } | |
| } | |
| public class UserService { | |
| private IUserRepository _userRepository; | |
| // receives a IUserRepository by dependency injection | |
| public UserService(IUserRepository userRepository) { | |
| _userRepository = userRepository; | |
| } | |
| public async Task PersisteUser(User user) { | |
| // a lot of code | |
| // bla bla bla | |
| // everything that needs to be done | |
| // finally persist user | |
| _userRepository.Insert(user); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment