使用适配器模式设计的第三方认证Oauth

时间:2015-06-03 21:33:57

标签: c# design-patterns ioc-container

我正在为facebook和google +编写第三方身份验证方法。

我决定使用适配器设计模式,这是我第一次遵循设计模式

这是我的设计结构

namespace ThirdPartyRegister.Tests
{
[TestClass]
public class ThirdPartyRegister
{
    [TestMethod]
    public void Login_Test()
    {
        IThirdPartyAuthenticationAdapter adapter= new ThirdPartyAuthenticationAdapter(new GooglePlusAuthentication());

        var testResult = adapter.Login();
        Assert.IsFalse(testResult);
    }
}

public interface IThirdPartyAuthenticationAdapter{
    bool Login();
 }

public class ThirdPartyAuthenticationAdapter : IThirdPartyAuthenticationAdapter
{
    private readonly IThirdPartyAuthenticationAdapter _thirdPartyAuthentication;

    public ThirdPartyAuthenticationAdapter (IThirdPartyAuthenticationAdapter thirdPartyAuthentication){
         _thirdPartyAuthentication = thirdPartyAuthentication;
    }

    public bool Login()
    {
        return _thirdPartyAuthentication.Login();
    }

}

public class GooglePlusAuthentication : IThirdPartyAuthenticationAdapter{
    public bool Login()
    {
        return false;
    }
}

public class FacebookAuthentication : IThirdPartyAuthenticationAdapter{
   public bool Login()
   {
      return true;
   }
}

}

我的问题是上面适用的方法吗?或者我错过了适配器设计模式的东西

0 个答案:

没有答案