Queries
Creating queries in EventFlow is simple.
First, create a value object that contains the data required for the query. In this example, we want to search for users based on their username.
1 2 3 4 5 6 7 8 9 |
|
Next, create a query handler that implements how the query is processed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
The last step is to register the query handler in EventFlow. Here we show the simple, but cumbersome version. You should use one of the overloads that scans an entire assembly.
1 2 3 |
|
Then, to use the query in your application, you need a reference
to the IQueryProcessor
, which in our case is stored in the
_queryProcessor
field.
1 2 3 |
|
Queries shipped with EventFlow
ReadModelByIdQuery<TReadModel>
: Supported by both the in-memory and MSSQL read model stores automatically as soon as you define the read model use using the EventFlow options for that store.InMemoryQuery<TReadModel>
: Takes aPredicate<TReadModel>
and returnsIEnumerable<TReadModel>
, making it possible to search all of your in-memory read models based on any predicate.