Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Last active December 12, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4746929 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4746929 to your computer and use it in GitHub Desktop.
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