Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
twadevs opened this issue Mar 22, 2021 · 2 comments

Comments

@twadevs
Copy link

twadevs commented Mar 22, 2021

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
@petrsvihlik
Copy link
Contributor

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.

@twadevs
Copy link
Author

twadevs commented Mar 22, 2021

Thanks, @petrsvihlik, that works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants