kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK

Home Page:https://www.nuget.org/packages/Kontent.Ai.Delivery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeliveryClientBuilder (without DI) returning LinkedItems with objects set to null

twadevs opened this issue · comments

Brief bug description

We are trying to create some integration tests using NUnit, using the DeliveryClientBuilder to create the client. But for some reason, it always returns the LinkedItems as objects set to null.

Using DI via our Web API (.Net 5) project, it all works fine and returns the LinkedItems set correctly to the strongly typed objects.

We tried using the DeliveryClientBuilder within the Web API project, but with the same results.

Repro steps

  1. Setup a DeliveryClient without DI, as per the documentation:
    var _client = DeliveryClientBuilder
    .WithOptions(builder => builder
        .WithProjectId("<YOUR_PROJECT_ID>")
	.UseProductionApi()
	.Build())
    .Build();
  1. Get a content item async with linked items:
await client.GetItemAsync<yourtype>("yourcodename").
  1. Notice that the LinkedItems returns as objects set to null.

image

Expected behaviour

LinkedItems should not be set to null.

image

Test environment

  • .Net 5, Web SDK, NUnit

Hi @twadevs ,
you need to use .WithTypeProvider(customTypeProvider) or services.AddSingleton<ITypeProvider, CustomTypeProvider>(); (if you're using dependency injection.

I recommend reading the following articles:

I updated some of the samples there to always contain the registration of an ITypeProvider.

The type provider allows runtime resolution of CLR types <-> Content types in Kontent.

Thanks, @petrsvihlik, that works.