Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
341 stars 44 forks source link

CosmosCollectionAttribute breaks POCO benefits #83

Open RobEyres opened 5 years ago

RobEyres commented 5 years ago

We're trying to refactor our Cosmos entity models to allow them to be reused over numerous projects / applications. One of the big problems introduced was that the entities are now marked up with [CosmosCollection] but we don't want to drag in a dependency to Cosmonaut everywhere the entities are referenced (the consuming libraries have nothing to do with Cosmos or storage concerns).

Would it be possible to abstract the concepts of "entity to collection mapping" and also partition key mapping away by providing an interface. E.g. By having a ICosmosEntityToCollectionMapper type class, the consumer can get away without having to mark up entities with Cosmonaut attributes.

Perhaps the default ICosmosEntityToCollectionMapper could rely on Cosmonaut attributes and fall back on convention as is the current behaviour.

Anyway...please let me know what you think. I could always spike this concept in a branch if this would help?

Elfocrash commented 5 years ago

Hey Rob,

Those are all solid points. I would like to see a more detailed example of your proposal to potentially add it as an alternative to the existing solution with the attribute.

RobEyres commented 5 years ago

Ok...give me a little time to flesh out a POC. Will get back to you. Thanks

roberino commented 5 years ago

Hey...I created a POC on a fork...take a look at IEntityConfigurationProvider and related implementations.

I think something like this will allow the collection and partition configuration to be defined completely separately from entities while still supporting the default attribute based configuration of entities.

https://github.com/roberino/Cosmonaut/tree/feature/collection-mapping

Elfocrash commented 5 years ago

I really like this approach. Feel free to clean it up, write tests and create a PR. Make sure it's backwards compatible.

roberino commented 5 years ago

Done :) https://github.com/Elfocrash/Cosmonaut/pull/97