Sobes.tech
Junior — Middle

Why is it undesirable to use LocalContext.current in business logic layers such as Use Case or repository?

sobes.tech AI

Answer from AI

Using LocalContext.current in business logic layers such as Use Case or repository is undesirable for several reasons:

  1. Violation of the principle of separation of concerns — the business layer should be independent of platform-specific or UI-specific details, and LocalContext.current is tied to the UI context.

  2. Testing difficulties — direct access to LocalContext complicates writing unit tests, as a specific environment context is required.

  3. Loss of portability and reusability — business logic tied to a specific context is more difficult to use in other parts of the application or on other platforms.

It is better to pass necessary data or contexts explicitly through function parameters or use dependency injection to keep the business layer clean and independent of the UI.

Why is it undesirable to use LocalContext.current in… - sobes.tech