thenativeweb / cqrs-sample

CQRS, EventSourcing, (DDDD) Sample in node.js
148 stars 50 forks source link

on setting up context readmodel not generating #17

Closed pawarvijay closed 8 years ago

pawarvijay commented 8 years ago

I had setup my repository for context implementation according to my previous #16

Steps that i followed to implement context: 1 : Used configuration like, context: 'context.name', aggregate: 'aggregate.name' in domain.defineCommand ({ , domain.defineEvent({ , eventDenormalizer.defineEvent({ 2 : structured directory for context manufacturing and aggregate item 3 : added context.js according to manufacturing context 4 : added context: { name: 'mycontext' } in command

On testing i found readmodel was not generating

On Further debugging i found some mismatch here

query.name = query.name || '';
query.version = query.version || 0;
query.aggregate = query.aggregate || null;
query.context = query.context || null;
var found = _.filter(this.viewBuilders, function (vB) {
  return vB.name === query.name &&
        (vB.version === query.version || vB.version === -1) &&
        (vB.aggregate === query.aggregate) &&
        (vB.context === query.context);
});

Due to context setup : query.aggregate = 'narration' & query.context = 'mycontext' but on other side in _.filter(this.viewBuilders ,it contains aggregate= null & context = null in all objects in array so nothing matches and it returns empty array

pawarvijay commented 8 years ago

to see if actually it works i changed

return vB.name === query.name && (vB.version === query.version || vB.version === -1) && (vB.aggregate === query.aggregate) && (vB.context === query.context);

to this

return vB.name === query.name

Note : this change is bad for context , but just for ( testing purpose/see whether it creates read model) i tried this

this creates a readmodel successfully

pawarvijay commented 8 years ago

:) sorry i missed some configurations

in viewbuilder for context here

    aggregate: 'salesinvoice',
    context: 'sales',

Fully working sample with context :+1: