Search code examples
asp.net-corejson-apiasp.net-core-3.1

JsonApiDotNetCore 4.0 has removed BuildResourceGraph from JsonApiOptions. What is the replacement?


I am migrating from .NET Core 2.2 to 3.1. In doing so, I have updated the JsonApiDotNetCore package from 3.1 to 4.0.0 alpha 4.

In 2.2, I used JsonApiDotNetCore 3.1 and was using BuildResourceGraph to add any JSON API resources to the resource graph. Code below:

IMvcCoreBuilder objMvcCoreBuilder = null;

objServices.AddJsonApi((objOptions) =>
{
    objOptions.BuildResourceGraph((objBuilder) =>
    {
        objBuilder
        .AddResource<Register>("registers")
        .AddResource<Client>("clients")   
        ;
    });
}, objMvcCoreBuilder);

But, I get the following error:

'JsonApiOptions' does not contain a definition for 'BuildResourceGraph' and no accessible extension method 'BuildResourceGraph' accepting a first argument of type 'JsonApiOptions' could be found (are you missing a using directive or an assembly reference?)

What is the replacement for BuildResourceGraph?


Solution

  • After digging through the JsonApiOptions.cs commit history on Git, I found the change:

    IMvcCoreBuilder objMvcCoreBuilder = null;
    
    objServices.AddJsonApi(
        options => options.Namespace = "api/v1",
        resources: resources =>
                    resources
                    .AddResource<Register>("registers")
                    .AddResource<Client>("clients")             
                    ,
        mvcBuilder: objMvcCoreBuilder
    );
    

    Go down to the /NoEntityFrameworkExample/Startup.cs file and you will see the diff that shows the change. Other than that, there is only a cryptic mention to renaming BuildResourceManager in the change log notes at the top of the site.

    https://github.com/json-api-dotnet/JsonApiDotNetCore/commit/7b8250bf5b9e64b91d8fa0357e915a1121eb6081#diff-d56ca61ff20d8be0b7cb20c9fd106d9f

    The revised version of the file is here:

    https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/7b8250bf5b9e64b91d8fa0357e915a1121eb6081/src/Examples/NoEntityFrameworkExample/Startup.cs