存储库是否应该负责更新存储在外部服务中的特定模型字段?

Should a respository be responsible to update specified field of model stored in external service?

我了解存储库应该负责存储库模式中的 CRUD。 我的问题是:存储库是否应该负责更新存储在外部服务中的模型的指定字段?

例如:

密码:

public class MainController
{
    IUserAccountService userAccountService; // injected

    public void Main ()
    {
        userAccountService.GetUsers ().Then (UpdateUserView);
    }

    // ...

    void OnUserAccountSelected (UserAccount selectedUserAccount, string newDisplayName)
    {
        userAccountService.UpdateDisplayName (selectedUserAccount, newDisplayName)
        .Then (UpdateUserView)
        .Catch<WordInDisplayNameNotAllowedException> (HandleWordInDisplayNameNotAllowedException)
        .Catch (HandleError);
    }
}

public class UserAccountService : IUserAccountSercie
{
    IUserAccountRepository repository; // injected

    // ...

    public Promise<UserList> GetUsers ()
    {
        return repository.GetAll ();
    }

    public UpdateDisplayName (UserAccount userAccount, string newDisplayName)
    {
        // Should I like the following?
        repository.UpdateDisplayName (userAccount, newDisplayName);
    }
}

public class UserAccountRepository : IUserAccountRepository
{
    public Promise<UserList> GetAll ()
    {
        // request to external web service...
    }

    public Promise<UserAccount> UpdateDisplayName (UserAccount userAccount, string newDisplayName)
    {
        // request to external web service...
    }
}

我应该把代码放在哪里调用 web API 来更新 UserAccount::displayName?

像这样的用例逻辑应该放在应用程序服务中。存储库应该只关心更新整个聚合。

我认为 将提供有关应用程序服务的足够信息,为您指明正确的方向。