Repository navigation
Closed
Milestone
Description
It had been decided in the past that we would:
- Keep metadata interfaces minimal with only “core”, non-computed concepts exposed
- Store non-core concepts as annotations
- Add extension methods to access non-core concepts and computed information
- Use caching when necessary to avoid expensive computation
- Expose caching through additional interfaces that could be probed for
This has resulted in the following issues:
- Our product code and tests only ever use our implementations, which means where an extension method does some probing it will always go down one path and not the other. We never test the other path, which may be completely broken. For example:
public static bool UseEagerSnapshots([NotNull] this IEntityType entityType)
{
Check.NotNull(entityType, nameof(entityType));
return (entityType as EntityType)?.UseEagerSnapshots ?? false;
}If the implementation of IEntityType is not ours, then this code will always return false. This is almost always wrong and will cause change tracking to not work.
- We often don’t probe for interfaces but instead for our concrete types. See the example above again. This means that even if this code was correct and was somehow able to compute a value for UseEagerSnapshots, if that computation was slow (which it would be) then there would be no way for some other implementation of IEntityType to use a cached value and obtain acceptable perf.
I think we should choose a way to be consistent and fix the code appropriately. Some options:
- Go all-in YAGNI and assert that the only implementation of our metadata interfaces for the foreseeable future will be our own implementation. In extension methods that probe have the path we don’t use throw saying you can’t do that, but you can submit a pull request exposing the behavior as an interface such that you can then do it.
- Go all in with the extensiblity mechanism and make sure that we don’t probe for concrete types and that the paths taken with other implementations actually work by writing and maintaining tests for them all. This is quite a lot of work.
- Go half in and drop the additional interfaces, but at least add tests for all implementations or our extension methods. This would allow somebody to implement our metadata, although probably not in a performant way.
Personally, I think we should go with all-in YAGNI. The interfaces we have provide a good read-only API surface, but I think as of now we should just assume that nobody else is implementing our metadata model. If and when somebody decides to do so we can take a path to make that work.
Activity
AndriySvyryd commentedon Apr 14, 2016
Another point to consider is that soon we could have a read-only model implementation for perf. Then the mutable model will not need to implement most of the optional interfaces and could be used for tests without much additional cost.
In the long-term we could consider using the compiled model generator to customize what combination of interfaces we use for tests.
ajcvickers commentedon Apr 20, 2016
@rowanmiller @divega @AndriySvyryd @anpete Draft exception message:
rowanmiller commentedon Apr 20, 2016
👍
Be explicit that custom metadata interface implementations are not ye…
Be explicit that custom metadata interface implementations are not ye…