You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In aggregate projections currently Apply(event, projectionInstance) methods are being called whenever event happens even though Create(otherEvent) has never been called on a projection because otherEvent never happened. This also means that projectionInstance passed to Apply(event, projectionInstance) is initialized with defaults.
Expected behaviour:
Only Create(event) projection methods should create projection instance in db, and if the event that would trigger Create never happened then Apply(event, projection) methods should be ignored.
Tested on Marten 7.36.0.
publicclassAdditionalCardholdersToBeAssignedProjection:MultiStreamProjection<AdditionalCardholdersToBeAssigned,string>{publicAdditionalCardholdersToBeAssignedProjection(){IncludeType<AdditionalCardholdersApproved>();Identity<IEvent<AdditionalCardholdersApproved>>(x =>x.StreamKey!);IncludeType<SubscriptionStartedThroughApprovedApplication>();Identity<SubscriptionStartedThroughApprovedApplication>(x =>x.MembershipApplicationId);IncludeType<MemberAssignedToSubscriptionThroughApprovedApplication>();Identity<MemberAssignedToSubscriptionThroughApprovedApplication>(x =>x.MembershipApplicationId);}}publicrecordAdditionalCardholdersToBeAssigned{[Identity]publicrequiredstringMembershipApplicationId{get;init;}// ...publicstaticAdditionalCardholdersToBeAssignedCreate(IEvent<AdditionalCardholdersApproved>approved){returnnewAdditionalCardholdersToBeAssigned(){MembershipApplicationId=approved.StreamKey!,AdditionalCardholders=approved.Data.AdditionalCardholders,ReadyToBeAssigned=false,};}publicstaticAdditionalCardholdersToBeAssignedApply(SubscriptionStartedThroughApprovedApplicationstarted,AdditionalCardholdersToBeAssignedcardholders){// This gets called event though Create has never been called before and "cardholders" is just initialized with default values.// I would expect for the apply only be ran when projection instance exists.returncardholderswith{ReadyToBeAssigned=true,SubscriptionId=started.SubscriptionId,};}// ...}
The text was updated successfully, but these errors were encountered:
@alekbarszczewski The quick workaround for you would be to shift to CustomProjection as your baseline and just write explicit code. I'm not 100% sure this will be worked on any time soon.
Got it, well my workaround for now is that I actually check if some not-nullable property that should have been initialized in Create() is actually null during Apply - if yes I return null.
public static AdditionalCardholdersToBeAssigned? Apply(MemberAssignedToSubscriptionThroughApprovedApplication assigned, AdditionalCardholdersToBeAssigned cardholders)
{
if (cardholders.MembershipApplicationId is null) return null; // if not set means Create was not called before
return cardholders with
{
AdditionalCardholders = cardholders
.AdditionalCardholders
.Where(x => x.ExistingMemberId != assigned.MemberId)
.ToArray()
};
}
In aggregate projections currently Apply(event, projectionInstance) methods are being called whenever event happens even though Create(otherEvent) has never been called on a projection because otherEvent never happened. This also means that projectionInstance passed to Apply(event, projectionInstance) is initialized with defaults.
Expected behaviour:
Only Create(event) projection methods should create projection instance in db, and if the event that would trigger Create never happened then Apply(event, projection) methods should be ignored.
Tested on Marten 7.36.0.
The text was updated successfully, but these errors were encountered: