-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: update MongoDB.Driver to 3.0.0 #23
base: master
Are you sure you want to change the base?
Conversation
In 3.0.0, all of Core has been merged into one, which is why we can drop dependency on `MongoDB.Driver.GridFS`. `GuidRepresentation` has also been altered, so now to get a default Guid representation behaviour, we must register a global `GuidSerializer` with a selected representation. Alternatively, a representation must be choosen on a per-field basis using annotations.
E.g. `net6.0`, `netstandard2.1` and `net472` MongoDB have dropped support for .Net Framework 4.6 and .Net Core 2.x (https://www.mongodb.com/docs/drivers/csharp/upcoming/upgrade/v3/#version-3.0-breaking-changes)
Well, there seems to be a potential breaking change here. Specifically MongoDb.Driver 3.0 requires explicit specification of So stuff like I tried playing around with just doing that - but it seems that So I'm unsure the best approach to handle this breaking change in Rebus. We can't just set up a global We can't just add a I guess the intended approach from MongoDB.Driver is that it must be made explicit, e.g. users of |
This is not intended for production - but PoC to see if I can get test suite green. Here I just assume all clients will be globally using `CSharpLegacy` representation. In reality, we need to address the now explicit choice of Guid representation that MongoDB.Driver enforces, which allows Guid's to be represented differently, even within the same document.
Please note, even though this PR is green - it's not actually production ready. This just demonstrates that we can upgrade to 3.0, but we need to figure out how to handle GuidRepresentation from now on. I have just configured it such that we are assuming Clients may also mix and match as they see fit, e.g. we could have a public async Task<ISagaData> Find(Type sagaDataType, string propertyName, object propertyValue)
{
var collection = await GetCollection(sagaDataType);
var value = propertyValue is Guid guid
? new BsonBinaryData(guid, GuidRepresentation.CSharpLegacy)
: BsonValue.Create(propertyValue);
var criteria = propertyName == nameof(ISagaData.Id)
? new BsonDocument { { "_id", value } }
: new BsonDocument { { propertyName, value } };
var result = await collection.Find(criteria).FirstOrDefaultAsync().ConfigureAwait(false);
if (result == null) return null;
return (ISagaData)BsonSerializer.Deserialize(result, sagaDataType);
} For I think for 3.x, when using the LINQ approach or using |
I think that enforcing I think that the following scenarios should be supported:
|
I agree, and in my opinion the first option seems the most "correct" by leaning against what the developers of The main pain point of that though, is the |
I have updated the PR with a proposed implementation. This requires the user to setup appropriate If they inherit from BsonClassMap.RegisterClassMap<SagaData>(map =>
{
map.MapIdMember(obj => obj.Id).SetSerializer(new GuidSerializer(GuidRepresentation.Standard));
map.MapMember(obj => obj.Revision);
}); If their inheriting class also contains BsonClassMap.RegisterClassMap<MySagaData>(map =>
{
map.MapMember(obj => obj.MyGuidProperty).SetSerializer(new GuidSerializer(GuidRepresentation.Standard));
}); If they inhertit from I opted to register a global |
@mookid8000 thoughts on this approach? Would be awesome to get |
In 3.0.0, all of Core has been merged into one, which is why we can drop dependency on
MongoDB.Driver.GridFS
.GuidRepresentation
has also been altered, so now to get a default Guid representation behaviour, we must register a globalGuidSerializer
with a selected representation.Alternatively, a representation must be choosen on a per-field basis using annotations.
Rebus is MIT-licensed. The code submitted in this pull request needs to carry the MIT license too. By leaving this text in, I hereby acknowledge that the code submitted in the pull request has the MIT license and can be merged with the Rebus codebase.