Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IAuthProvider
- {
- AuthResult Authenticate(string username, string password);
- }
- public class DbAuthProvider : IAuthProvider
- {
- public AuthResult Authenticate(string username, string password)
- {
- // Do authentication against database
- }
- }
- public class LdapAuthProvider : IAuthProvider
- {
- public AuthResult Authenticate(string username, string password)
- {
- // Do authentication against LDAP
- }
- }
- /** in our controller **/
- public class LoginController
- {
- private IAuthProvider authProvider;
- public LoginController()
- {
- // We can instantiate the implementation of auth provider here
- // in the constructor
- authProvider = new DbAuthProvider();
- // Or better yet, use an IoC so the implementation can be
- // configured elsewhere.
- authProvider = IoC.GetInstance<IAuthProvider>();
- }
- public object Login(string username, string password)
- {
- // use authProvider
- authProvider.Authenticate(username, password);
- // bla.. bla.. bla..
- }
- }
Add Comment
Please, Sign In to add comment