You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is that really the case? What is the intended procedure for providers to implement their own model customization without disturbing other extensions or custom user code that implements IModelCustomizer (especially in later releases like now)?
We currently implemented JSON support in Pomelo for both, System.Text.Json and Newtonsoft.Json, based on the work done by @roji for Npgsql. The support is implemented in individual packages (one for each supported JSON library) and based on the underlying plugin infrastructure (like for the NTS implementation).
Newtonsoft.Json uses a couple of DOM classes with properties that would normally be discovered as navigation properties by EF Core. We don't want that, because those classes and properties are being explicitly handled and translated by the query pipeline. It seems that the intended way to solve this problem is to implement IModelCustomizer and ignore the types.
Doing so at this point in time could however break other extensions that users might already be using and existing user code that depends on their own IModelCustomizer implementation.
We would also need different IModelCustomizer implementations, a MySqlJsonMicrosoftModelCustomizer and a MySqlJsonNewtonsoftModelCustomizer, of which one would be registered with DI for IModelCustomizer, depending on the JSON library actual used.
That means that users and extension would potentially not only need to override just one provider specific implementation in our case, but both if they would want to support both JSON libraries, if they want to use their own IModelCustomizer as well.
There seem to be some solutions to this issue for us:
Just override IModelSource instead (which should much more unlikely be already implemented by extensions or user code), let the provider specific model customizers implement a provider specific interface like IMySqlModelCustomizer that allows for multiple registrations, and then explicitly call all those provider specific model customizers in IModelSource.GetModel() in addition to the official IModelCustomizer implementation.
Allow multiple registrations for IModelCustomizer itself.
Shouldn't IModelCustomizer allow multiple registrations in the first place?
@lauxjpn You can do it in an IModelInitiliazed convention. IModelCustomizer should only be implemented if you need access to the context instance when creating the model.
@AndriySvyryd Thanks, I totally missed that option! This works much better than the first approach I outlined, because then we also would have wanted to use our own MySqlTestModelSource class when testing, which is simple to do for individual test fixtures, but hard to do an a global level for all test fixtures, because of its tight coupling to FixtureBase.
Activity
divega commentedon Aug 4, 2017
@AndriySvyryd do you think we need to do this in 2.1 or is ok to have it in the backlog?
AndriySvyryd commentedon Aug 4, 2017
@divega Backlog is fine
ajcvickers commentedon Aug 23, 2017
Moving this to 2.1 based on feedback in #9225.
Allow multiple IModelCustomizer
Allow multiple IModelCustomizer
Allow multiple IModelCustomizer
AndriySvyryd commentedon Sep 7, 2017
This will be covered by #626
lauxjpn commentedon Sep 6, 2020
Is that really the case? What is the intended procedure for providers to implement their own model customization without disturbing other extensions or custom user code that implements
IModelCustomizer(especially in later releases like now)?We currently implemented JSON support in Pomelo for both,
System.Text.JsonandNewtonsoft.Json, based on the work done by @roji for Npgsql. The support is implemented in individual packages (one for each supported JSON library) and based on the underlying plugin infrastructure (like for the NTS implementation).Newtonsoft.Jsonuses a couple of DOM classes with properties that would normally be discovered as navigation properties by EF Core. We don't want that, because those classes and properties are being explicitly handled and translated by the query pipeline. It seems that the intended way to solve this problem is to implementIModelCustomizerand ignore the types.Doing so at this point in time could however break other extensions that users might already be using and existing user code that depends on their own
IModelCustomizerimplementation.We would also need different
IModelCustomizerimplementations, aMySqlJsonMicrosoftModelCustomizerand aMySqlJsonNewtonsoftModelCustomizer, of which one would be registered with DI forIModelCustomizer, depending on the JSON library actual used.That means that users and extension would potentially not only need to override just one provider specific implementation in our case, but both if they would want to support both JSON libraries, if they want to use their own
IModelCustomizeras well.There seem to be some solutions to this issue for us:
Just override
IModelSourceinstead (which should much more unlikely be already implemented by extensions or user code), let the provider specific model customizers implement a provider specific interface likeIMySqlModelCustomizerthat allows for multiple registrations, and then explicitly call all those provider specific model customizers inIModelSource.GetModel()in addition to the officialIModelCustomizerimplementation.Allow multiple registrations for
IModelCustomizeritself.Shouldn't
IModelCustomizerallow multiple registrations in the first place?AndriySvyryd commentedon Sep 6, 2020
@lauxjpn You can do it in an IModelInitiliazed convention. IModelCustomizer should only be implemented if you need access to the context instance when creating the model.
lauxjpn commentedon Sep 6, 2020
@AndriySvyryd Thanks, I totally missed that option! This works much better than the first approach I outlined, because then we also would have wanted to use our own
MySqlTestModelSourceclass when testing, which is simple to do for individual test fixtures, but hard to do an a global level for all test fixtures, because of its tight coupling toFixtureBase.