所以我有一个接口如下
public interface IMembershipProvider
{
bool GetUserGuidFromSSOToken(string ssoToken, out string userGuid, out int statusCode);
}
实现上述接口的后续类
public class MembershipProvider : IMembershipProvider
{
public bool GetUserGuidFromSSOToken(string ssoToken, out string userGuid, out int statusCode)
{
....Method Contents
}
}
然后在我的演示者中,我有以下
private IMembershipProvider Provider;
..
if (!Provider.GetUserGuidFromSSOToken(ObSSOCookie.Value, out userGuid, out statusCode))
当调用它时,它使用MembershipProvider类中的方法的代码,但我只是想知道在Presenter中从未引用MembershipProvider时该怎么做?
答案 0 :(得分:1)
必须使用依赖注入将MembershipProvider实例注入Presenter。
答案 1 :(得分:1)
某种服务工厂提供商通常就是我所做的。
private IMembershipProvider Provider =
MembershipProviderService.GetDefaultProvider();
...
internal class MembershipProviderService
{
IMembershipProvider GetDefaultProvider()
{
return new MembershipProvider();
}
}