Result package
In one of my projects, I already have the Entity and ValueObject base implementations (I guess this is very common, right?) that differ from the ones provided by this package.
Now I would like to start using Result from this repo with those entities.
If I do so, I start having naming collisions, besides the possibility of pointing to the wrong implementation of those classes by mistake.
Would it be a possibility to serve the Result library from its own dedicated base project+package? :}
You can manage this inconsistency using namespaces, like this:
using LibraryEntity = CSharpFunctionalExtensions.Entity;
using LibraryValueObject = CSharpFunctionalExtensions.ValueObject;
Though I understand this is an inconvenience. What is the difference between your and library's implementations of Entity and VO?
meh, tiny details, I guess:
Entity:
- uses NRT
- The .sln I work on has this silly convention of suffixing all id properties with
IDinstead ofId🙄 - Regarding hash code generation, I'm following this one that doesn't cover proxies (I don't use NHibernate nor EF Core Lazy Loading), so it doesn't need to perform runtime reflection at every hash calculation.
The whole point of GetHashCode is to optimize a lookup operation; if the call to GetHashCode is slower than looking through those ten thousand items one at a time, then you haven’t made a performance gain. https://ericlippert.com/2011/02/28/guidelines-and-rules-for-gethashcode/
ValueObject:
- idem NRT
- idem no proxies
- from the same ebook repo, the only needed abstract is GetEqualityComponents() (instead of 2 methods) and the usage is by yielding the components. It may not be as customizable, but it suited my needs.
I've ended up adding your package anyway 🍻 and just added some paranoid code that will make EF throw if it encounters classes derived from CSharpFunctionalExtensions during OnModelCreating(), to avoid mix-ups lol
Btw, your courses, blog posts, repos are all very valuable! kudos and thank you!
Thanks for the kind words.
- Regarding
ValueObject, there are 2 versions in CSharpFunctionalExtensions: one with a generic parameter (for more customization) and another one without, which is exactly the same as the version from eShopOnContainers:
- https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/8171649c1b7f41dd2ee4f135433a470daa59e567/CSharpFunctionalExtensions/ValueObject/ValueObject.cs#L12
- https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/8171649c1b7f41dd2ee4f135433a470daa59e567/CSharpFunctionalExtensions/ValueObject/ValueObject.cs#L62
By the way, it looks like eShopOnContainers refactored their version to match mine, I remember them having another implementation in the past (indeed, they did: https://github.com/dotnet-architecture/eShopOnContainers/pull/1316/files )
-
Could you elaborate on how your versions use NRT?
-
Regarding no proxies in
GetHashCode-- that's a good point. If you could do a PR, I will merge it.