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
- Setup a DeliveryClient without DI, as per the documentation:
var _client = DeliveryClientBuilder
.WithOptions(builder => builder
.WithProjectId("<YOUR_PROJECT_ID>")
.UseProductionApi()
.Build())
.Build();
- Get a content item async with linked items:
await client.GetItemAsync<yourtype>("yourcodename").
- Notice that the LinkedItems returns as objects set to null.
Expected behaviour
LinkedItems should not be set to null.
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:
- Registering the DeliveryClient to the IServiceCollection in ASP.NET Core
- Strong Types Explained – Code Generator
- Working with strongly typed models
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.