Book Image

Learning NServiceBus - Second Edition

By : David Boike
Book Image

Learning NServiceBus - Second Edition

By: David Boike

Overview of this book

Table of Contents (18 chapters)
Learning NServiceBus Second Edition
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding saga data


Wait a second! We said that IAmStartedByMessages<T> tells the saga to create a new saga instance if the existing saga data is not found, but how does it know where to look for the saga data?

As it turns out, we need to give NServiceBus a bit of help with this, by telling it how to match message properties with saga data. Because the ConfigureHowToFindSaga method is now abstract in 5.0, we have already created it, but now we have to fill in the details using the mapper object it provides:

mapper.ConfigureMapping<CreateNewUserCmd>(msg => msg.EmailAddress)
    .ToSaga(data => data.EmailAddress);

The ConfigureMapping<TMessageType> method accepts an Expression (a specialized lambda expression that can be evaluated at runtime) that identifies a property on the incoming message to match with the saga data. Then, with the result, we call the ToSaga method that accepts a similar expression pointing to the matching property in the saga data. So in essence, this...