efacilitation/eventric

Inject $projection into Command-/QueryHandler

Closed this issue · 1 comments

As a (Query/Command)Handler
I want to access Projections directly
So that I don't have to use ProjectionStores but can use the Projection itself instead


Projections by Name

someContext.addProjection 'SomeProjection', ->
  handleSomethingHappened: ->
    @something = 'Ender'

someContext.initialize ->

This will initialize the previously added Projection. To now access the Projection from say a QueryHandler, one should be able to do something like

someContext.addQueryHandler 'getSomething', (params, promise) ->
  @$projectionByName 'SomeProjection'
  .then (projection) ->
    promise.resolve projection.something

Projections are only available by name if they got automatically initialized from the Context.

Projections by ID

someContext.initialize ->

  someContext.initializeProjection
    handleSomethingHappened: ->
      @something = 'Ender'
  .then (projectionId) ->
    # ...

This will initialize a Projection without a Name or previously added ProjectionClass (addProjection). If one now wants to access the Projection inside a QueryHandler, it should be possible to do something like this:

someContext.addQueryHandler 'getSomething', (params, promise) ->
  @$projectionById projectionId
  .then (projection) ->
    promise.resolve projection.something

Closing for now (see #33). Will come up again if required.