serradura/u-case

Allow dependency injection in static flows

serradura opened this issue · 0 comments

The u-case allows the usage of dependency injection via the #then method, its method is used to declare dynamic flows.

Group::FindAllForUser
  .call(user: current_user, params: params)
  .then(Paginate)
  .then(Serialize::PaginatedRelationAsJson, serializer: Group::Serialize)

e.g: # https://github.com/EliezerSalvato/financial_control/blob/7c9e3d4547d58b307109c6adf0634869b76d5c89/app/controllers/api/v1/groups_controller.rb#L3-L7

The idea of this issue is to propose the creation of a mechanism to allow dependency injection in static flows. Like these examples:

FetchListAsJson = Micro::Cases.flow([
  Group::FindAllForUser,
  Paginate,
  [Serialize::PaginatedRelationAsJson, serializer: Group::Serialize]
])

FetchListAsJson = Micro::Cases.safe_flow([
  # ...
])
class FetchListAsJson < Micro::Case
  flow [
    Group::FindAllForUser,
    Paginate,
    [Serialize::PaginatedRelationAsJson, serializer: Group::Serialize]
  ])
end

class FetchListAsJson < Micro::Case::Safe
  flow [
    # ...
  ])
end