Last active
December 12, 2015 08:49
-
-
Save yetanotherchris/4746929 to your computer and use it in GitHub Desktop.
Façade design pattern example
This file contains 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 class UserManager | |
{ | |
// The main implementation of IRepository would be internal to your Core/Domain project, | |
// so consumers of your API couldn't change the database directlry without going through | |
// your façade classes. | |
private IRepository _repository; | |
public UserManager() | |
{ | |
_repository = new SqlRepository("some connection string from a config file"); | |
} | |
public UserManager(IRepository repository) | |
{ | |
_repository = repository; | |
} | |
public User GetById(Guid id) | |
{ | |
return _repository.ExecuteSql<User>("SELECT * FROM User WHERE Id=@Id", id) | |
} | |
public User GetByEmail(string email) | |
{ | |
return _repository.ExecuteSql<User>("SELECT * FROM User WHERE Email=@Email", email) | |
} | |
// more methods User-specific methods. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment