kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 43 forks source link

Feedback needed: People are omitting ITypeProvider registration #239

Open petrsvihlik opened 4 years ago

petrsvihlik commented 4 years ago

Motivation

We receive a lot of various error reports (on StackOverflow, GitHub, support chat on intercom) that all have one common denominator: they are caused by a missing registration of the ITypeProvider implementation.

There are more ways to register the implementation and they are described here: https://github.com/Kentico/kontent-delivery-sdk-net/wiki/Working-with-strongly-typed-models#adding-support-for-runtime-type-resolution

For simplicity (and historical reasons), the registration is not included in the README (so probably a lot of people miss it at that point). The fact is that the ITypeProvider is not required for the simplest scenarios such as retrieving a 1st level model without complex types. However, for anything more complex (linked items, rich text, etc.) it absolutely necessary to have it registered.

Proposed solution

We have a few options:

  1. link the wiki page from the readme
  2. make the readme a bit longer and add the registration there + link the wiki page
  3. move all best practices to README
  4. implement automatic lookup of ITypeProvider (in calling assemblies) and allow developers to override it
  5. make the registration of ITypeProvider mandatory and throw an exception if omitted
  6. something else???

Your opinion

Let us know what would be an appropriate solution for you (if you were a new user of the SDK).

vletierce commented 4 years ago

Hi, I have been using the SDK over a year now and must say the fact that I can't assigned a custom type provider to a named HttpClient through the .NetCore dependency injection mechanisme represents a real problem on my side. There is the possibility to create an instance of a SharedTypeProvider class however it only works if all your content types (accross projects) have different names, unfortunately in my case I have content types that share the same name accross projects.

Could we have quick exemple of what solution 4 would look like ? In my case it is very important that I can match a content type provider to a specific named client.

Thanks

petrsvihlik commented 4 years ago

Hi @vletierce, thanks for your feedback. You probably wanted to comment on this one: https://github.com/Kentico/kontent-delivery-sdk-net/issues/240 (see problem no. 2)

Please check out the suggested approach and let us know if it's viable for you.

petrsvihlik commented 3 years ago

e.g. #271