prism v5服务层请求用户输入

时间:2014-10-15 14:45:00

标签: prism

我的Prism V5 WPF应用程序中的我的身份验证服务层(OAuth)将处理已经过身份验证并准备用于数据调用的Http客户端的创建。在一些情况下,服务层可以从服务器接收消息,指示用户需要重新提供其登录凭证以便继续与服务器通信。 pubsub事件的服务火灾说“有人从我这里得到了一些信用”。 UI组件将接收该消息并与用户交互,并以某种方式将凭证传递回服务,以便它可以继续。我的架构可能有点不对劲。什么是服务处理额外用户输入需求的最佳方式,并在收到用户输入时进行处理。我的服务层可能会在下面进行此调用。

    private UserCredentials AskUserForCredentials()
    {
        _eventAggregator.GetEvent<LoginCredentialsRequested>().Publish(new LoginCredentialsRequestedEventArgs());

       // wait for the input and return it here...
    }

1 个答案:

答案 0 :(得分:0)

创建互动服务,代表您完成工作。然后将包括任何所需验证的用户交互封装在单独的服务组件中。您的身份验证服务通过您使用的任何依赖注入机制接收对交互服务的引用,而不是发布事件,身份验证服务只是在交互服务上调用适当的方法来请求UserCredentials。

public interface IUserCredentialsInteractionService
{
    UserCredentials GetUserCredentials();
}

public class AuthenticationService
{
    IUserCredentialsInteractionService _interactionService;

    public AuthenticationService(IUserCredentialsInteractionService interactionService)
    {
        _interactionService = interactionService;
    }

    private UserCredentials AskUserForCredentials()
    {
        UserCredentials credentials = _interactionService.GetUserCredentials();
    }
}

交互服务只是您在prism框架中实现的另一个组件,但它本身可以使用prism InteractionRequest对象在其自己的视图模型和视图之间进行通信。

相关问题