Guest User

Untitled

a guest
Sep 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. public interface IAuthProvider
  2. {
  3. AuthResult Authenticate(string username, string password);
  4. }
  5.  
  6. public class DbAuthProvider : IAuthProvider
  7. {
  8. public AuthResult Authenticate(string username, string password)
  9. {
  10. // Do authentication against database
  11. }
  12. }
  13.  
  14. public class LdapAuthProvider : IAuthProvider
  15. {
  16. public AuthResult Authenticate(string username, string password)
  17. {
  18. // Do authentication against LDAP
  19. }
  20. }
  21.  
  22. /** in our controller **/
  23.  
  24. public class LoginController
  25. {
  26. private IAuthProvider authProvider;
  27.  
  28. public LoginController()
  29. {
  30. // We can instantiate the implementation of auth provider here
  31. // in the constructor
  32. authProvider = new DbAuthProvider();
  33.  
  34. // Or better yet, use an IoC so the implementation can be
  35. // configured elsewhere.
  36. authProvider = IoC.GetInstance<IAuthProvider>();
  37. }
  38.  
  39. public object Login(string username, string password)
  40. {
  41. // use authProvider
  42. authProvider.Authenticate(username, password);
  43. // bla.. bla.. bla..
  44. }
  45. }
Add Comment
Please, Sign In to add comment