Skip to content

Adds support for free-format client-generated IDs #10

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

Closed
wants to merge 2 commits into from

Conversation

bart-degreed
Copy link
Contributor

Adds support for free-format client-generated IDs, by introducing MongoStringIdentifiable side-by-side with MongoObjectIdentifiable (formerly MongoIdentifiable), both implementing the marker interface IMongoIdentifiable.

Based on the work described in #7, I tried to change existing tests for client-generated IDs to use free-format IDs by overwriting the annotations with fluent mappings. But I was unable to overwrite the Id property, because it is defined in base class (override did not help).

@alastairtree @mrnkr I'm curious if you believe this a good solution. I'm very open to feedback, as I'm not using MongoDB myself.

I'll update the docs before merge, but wanted to get this out soon to gather feedback.

Bart Koelman added 2 commits March 18, 2021 19:52
…goStringIdentifiable side-by-side with MongoObjectIdentifiable (formerly MongoIdentifiable), both implementing the marker interface IMongoIdentifiable.
@mrnkr
Copy link
Contributor

mrnkr commented Mar 19, 2021

I honestly like what you did here. I find that it did not add that much complexity to the library while still allowing users to send free-format strings and use them as IDs. Gotta say I would have liked to be able to do the same you do with Identifiable in JsonApiDotNetCore and pass in a generic to define the type of the Id attribute but of course I understand why that was not possible.

I did have to take a minute to wrap my head around which was which between the two implementations of IMongoIdentifiable. The docs do help but I was wondering whether it would work to leave the previous implementation as default using the same name and add MongoStringIdentifiable as the new one. Wouldn't that also make the cost of migrating to a new version including this upgrade less? What are your thoughts?

Anyway, I was just being nitpicky earlier, good job!

@bart-degreed
Copy link
Contributor Author

Thanks @mrnkr for chiming in.

First of all, the breaking change should not matter much as we're still in alpha.

Having MongoIdentifiable and MongoStringIdentifiable makes me think the latter is a specialization or special-case of the former. I'd like to express that one is not better than the other, enforcing users to understand and choose which one is appropriate.

It is basically choosing between two ID formats: hex or free-format. I do realize the hex one is more common when using MongoDB, but I'm not sure that warrants having a shorter name.

Perhaps having MongoIdentifiable and FreeFormatStringMongoIdentifiable would work. Naming is hard, suggestions welcome. I'm also wondering if we can expect other variations to pop up in the future, and how they relate to these two.

Either way, I'd like to describe these two ID types on the repo readme to clarify their intent.

@mrnkr
Copy link
Contributor

mrnkr commented Mar 22, 2021

The last idea you proposed is nice, the one about MongoIdentifiable and FreeFormatStringMongoIdentifiable, it's a mouthful but a descriptive one hehe.

I don't know if there could be other variations, I would tend to say there could be none but I'd be claiming to be more knowledgeable than I actually am.

@bart-degreed
Copy link
Contributor Author

Superseded by #14.

@bart-degreed bart-degreed deleted the free-format-ids branch December 20, 2021 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants