Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Façade design pattern example
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
You can’t perform that action at this time.