Class ODataExtensions
These extensions are required to make sure all URI's that our OData replies expose are relative to Yarp's address, not the address of our local service.
public static class ODataExtensions
- Inheritance
-
ODataExtensions
- Inherited Members
Methods
AddODataSerializerBaseAddress(IServiceCollection, Uri)
Make sure that the service root URI used in OData serialization points to the endpoint used by external consumers (as understood by YARP). OData can embed URI's to its own service in some scenarios, like pagination ("@odata.nextLink"). Call this method when setting up OData when configuring our service collection.
public static IServiceCollection AddODataSerializerBaseAddress(this IServiceCollection configureServices, Uri odataBaseAddress)
Parameters
configureServicesIServiceCollectionThe service collection associated with the OData route components
odataBaseAddressUriThe base address of the service as seen by external consumers (i.e. from the point of view of YARP) Can be null if the service is being tested standalone, not behind YARP.
Returns
- IServiceCollection
The service collection passed as parameter
Examples
services.AddControllers() ... .AddOData(options => options ... .AddRouteComponents("odata", ODataModel.GetEdmModel(), configureServices => configureServices.AddODataSerializerBaseAddress(odataBaseAddress)) ) ...
SetODataFormattersBaseAddress(MvcOptions, Uri)
Make sure OData's metadata URI's ("@odata.context") point to the endpoint used by external consumers (as understood by YARP).
public static MvcOptions SetODataFormattersBaseAddress(this MvcOptions options, Uri odataBaseAddress)
Parameters
optionsMvcOptionsThe MVC configuration options
odataBaseAddressUriThe base address of the service as seen by external consumers (i.e. from the point of view of YARP) Can be null if the service is being tested standalone, not behind YARP.
Returns
- MvcOptions
The MVC configuration options passed as parameter
Examples
services.AddControllers() ... .AddOData(...) ... .AddMvcOptions(options => options.SetODataFormattersBaseAddress(odataBaseAddress));