简体   繁体   中英

Why is Kentico-Kontent .NET SDK running in Blazor WebAssembly GetItemsAsync<T>() returning items of all types?

I have been trying out Blazor WebAssembly and attempting to connect to an existing Kentico Kontent API.

I generated models using the DotNet Tool KontentModelGenerator which I then pass to Kentico's IDeliveryClient implementation.

@code{
    private IEnumerable<DinghyClass> dinghyClasses;
    protected override async Task OnInitializedAsync()
    {
        dinghyClasses = (await deliveryClient.GetItemsAsync<DinghyClass>()).Items;
    }
}

This then returns every item in the Kentico project (ie of all types of content model), rather than just those of the requested type.

Am I doing something wrong? Is this an issue with Kentico's DeliveryClient , or with how Blazor interprets it? The fact there are some half-populated objects created from the returned data suggests that the Javascript is populating the objects without any form of type-checking.

I have a example on GitHub which is deploying Here . The page should list the 5 dinghy classes, but rather has an (empty) object for every other content item as well. When looking at the Network tab on the chrome debugger, all items are being returned, not just the DinghyClass items.

In looking at (and testing) the code in your GitHub repository, it seems you have generated a CustomTypeProvider but it is not registered in Program.cs. When I added:

builder.Services.AddSingleton<ITypeProvider, CustomTypeProvider>();

to Program.cs in your solution, the SDK returned the 5 dinghy class results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM