prism v5服务层请求用户输入



我的Prism V5 WPF应用程序中的身份验证服务层(OAuth)将处理Http客户端的创建,该客户端已通过身份验证并可用于数据调用。在一些情况下,服务层可以从服务器接收指示用户需要重新提供他们的登录凭证以便继续与服务器通信的消息。该服务启动了一个pubsub事件,上面写着"有人从用户那里给我一些可信度"。UI组件将接收该消息并与用户交互,并以某种方式将凭据传递回服务,以便它可以继续运行。我可能在架构上有点错误。服务处理对额外用户输入的需求并在接收到来自用户的输入时进行处理的最佳方式是什么。我的服务层可能会在下面进行此调用。

    private UserCredentials AskUserForCredentials()
    {
        _eventAggregator.GetEvent<LoginCredentialsRequested>().Publish(new LoginCredentialsRequestedEventArgs());
       // wait for the input and return it here...
    }

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

public interface IUserCredentialsInteractionService
{
    UserCredentials GetUserCredentials();
}
public class AuthenticationService
{
    IUserCredentialsInteractionService _interactionService;
    public AuthenticationService(IUserCredentialsInteractionService interactionService)
    {
        _interactionService = interactionService;
    }
    private UserCredentials AskUserForCredentials()
    {
        UserCredentials credentials = _interactionService.GetUserCredentials();
    }
}

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

最新更新