【问题标题】:Where should WorkManager be placed within Clean Architecture?Where should WorkManager be placed within Clean Architecture?
【发布时间】:2022-12-27 14:35:43
【问题描述】:

I created a WorkManager that retrieves the current Bitcoin price from an API every 60 minutes and displays it to the user as a notification. However, I am confused about how to integrate WorkManager with Clean Architecture.

I created an infrastructure layer for WorkManager. Do you think this is correct? In your opinion, where should WorkManager be placed in Clean Architecture?

Scheme of Current Architecture

Package Structure

【问题讨论】:

  • Please stare some code or a schema of your current architecture. How do we know, is your architecture correct or not, if we cannot see it? :)
  • I added a scheme of current architecture

标签: android android-workmanager clean-architecture


【解决方案1】:

Its totally depend on your usecase, if its Business-oriented operations also if you follow official docs then its Data layer

【讨论】:

    【解决方案2】:

    From an architectural perspective a work manager is similar to a user interaction. If you wouldn't have a work manger, you would probably let the user trigger the "update bitcoin price" use case with an refresh button. You would register an event listener to the refresh button and invoke a controller when the event is emitted. Thus I would let the work manager invoke the controller.

    If your application is divided into a frontend client and backend server part. You have two options. Either let the frontend client use a work manager and send requests every X minutes or implement the work manager on the backend server controller side. But then you need a way to publish the results to the client, either through websockets or let the client poll.

    【讨论】:

      猜你喜欢
      • 2014-11-13
      • 2022-12-01
      • 2018-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      相关资源
      最近更新 更多