Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties of ISagaData documents are locked to pascal casing #5

Closed
ctcoulter opened this issue Mar 23, 2020 · 2 comments
Closed

Properties of ISagaData documents are locked to pascal casing #5

ctcoulter opened this issue Mar 23, 2020 · 2 comments

Comments

@ctcoulter
Copy link

Due to using strings instead of properties in a BsonDocument filter, compatibility with the CamelCaseElementNameConvention is lost.

Since I rely on camel casing for all other MongoDb actions (conventions applied globally), the only way I'm able to get around this currently is applying a custom class map for each SagaData implementation, which is obviously not ideal :(

Example:
https://github.com/rebus-org/Rebus.MongoDb/blob/master/Rebus.MongoDb/MongoDb/Sagas/MongoDbSagaStorage.cs#L103

var criteria = Builders<BsonDocument>.Filter.And(
    Builders<BsonDocument>.Filter.Eq("_id", sagaData.Id),
    Builders<BsonDocument>.Filter.Eq(nameof(ISagaData.Revision), sagaData.Revision)
);

Using Filter.Where instead of Filter.Eq would get around this, but I think you'd need to be strongly typed instead of using BsonDocument in order to do that.

This would also be an issue in the BSON validation:

https://github.com/rebus-org/Rebus.MongoDb/blob/master/Rebus.MongoDb/MongoDb/Sagas/MongoDbSagaStorage.cs#L247-L250

if (!target.Contains("Revision"))
{
    throw GetException("could not find 'Revision' in the serialied BSON document");
}

^ this one might be fixed just by doing something like this instead.

if (!target.Any(x => x.Name.Equals("Revision", StringComparison.InvariantCultureIgnoreCase)))
@mookid8000
Copy link
Member

Sorry @ctcoulter , but due to the design of MongoDB's BSON serializer, it's not possibly for Rebus to support all customizations – that's why it does a check on a dummy-serialized empty saga instance to see, if the expected fields can be found in the resulting BSON document.

But.... thingking of it now, I think it could be possible for Rebus' MongoDB saga persister to figure out the exact BSON field names by doing a dummy serialization (like it already does) and then remember the names of the resulting fields with the correct casing.

If you're interested in contributing this, please feel free to send a PR 🙂

@mookid8000
Copy link
Member

btw I've created #6 to track this work 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants