for notes with explanation.
Startup.cs
using System;
using System.Linq;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNet.OData.Extensions;
using Microsoft.AspNet.OData.Builder;
using OdataDemo.Models;
using Microsoft.OData.Edm;
namespace OdataDemo
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
Thursday, June 4, 2020
.Net Core 3.1 with oData
I have been cracking my head trying to solve following mysteries.
"@odata.count" is not show in the return result even after using $count=true.
odata is returning a list of object instead of in the odata format:
this:
[
{"id":"e313596c-8fe9-4db6-b7cb-84f2e059447b","name":"Cody Allen","score":130},{"id":"349a4642-82bd-440f-a05b-ed27ed60cade","name":"Viral Pandya","score":140},{"id":"44fe2696-5285-470f-8b4c-ad983e5241b4","name":"student3","score":120},
{"id":"f2e9d6b7-6825-435b-a86a-37ac89ef77cb","name":"student4","score":150},
{"id":"3a4982f3-a9f3-4bc7-8886-315e7082fd59","name":"student5","score":100}
]
instead of this:
{
"@odata.context":"https://localhost:44372/odata/$metadata#Students",
"@odata.count":5,
"value":[
{"Id":"445bb0cf-efe8-4420-af43-75b37d81dc13","Name":"Cody Allen","Score":130},{"Id":"ec9acefd-1b38-4a0e-aba0-de9949f6690f","Name":"Viral Pandya","Score":140},{"Id":"675ba6a5-c799-4df6-a820-15cb274c33a1","Name":"student3","Score":120},
{"Id":"6fec0f6c-60b6-4624-ad11-38443e0e077f","Name":"student4","Score":150},
{"Id":"a6eeeeb1-8d55-4418-9ab8-4df448a6e1f0","Name":"student5","Score":100}
]}
"@odata.count" is not show in the return result even after using $count=true.
odata is returning a list of object instead of in the odata format:
this:
[
{"id":"e313596c-8fe9-4db6-b7cb-84f2e059447b","name":"Cody Allen","score":130},{"id":"349a4642-82bd-440f-a05b-ed27ed60cade","name":"Viral Pandya","score":140},{"id":"44fe2696-5285-470f-8b4c-ad983e5241b4","name":"student3","score":120},
{"id":"f2e9d6b7-6825-435b-a86a-37ac89ef77cb","name":"student4","score":150},
{"id":"3a4982f3-a9f3-4bc7-8886-315e7082fd59","name":"student5","score":100}
]
instead of this:
{
"@odata.context":"https://localhost:44372/odata/$metadata#Students",
"@odata.count":5,
"value":[
{"Id":"445bb0cf-efe8-4420-af43-75b37d81dc13","Name":"Cody Allen","Score":130},{"Id":"ec9acefd-1b38-4a0e-aba0-de9949f6690f","Name":"Viral Pandya","Score":140},{"Id":"675ba6a5-c799-4df6-a820-15cb274c33a1","Name":"student3","Score":120},
{"Id":"6fec0f6c-60b6-4624-ad11-38443e0e077f","Name":"student4","Score":150},
{"Id":"a6eeeeb1-8d55-4418-9ab8-4df448a6e1f0","Name":"student5","Score":100}
]}
Friday, May 8, 2020
Read appsettings.json in .net Core application with Dependency Injection (DI)
If you are truggling on how to read a constant setting or any setting value into a custom class / or any POCO class from the appsettings, and passing them back to the application that use .netCore and support DependencyInjection, then you are looking at the right post.
I have been struggling on this and here is what I found out.
In your webApp project, go to the Startup.cs, go to the method ConfigureServices, and add the following code:
it can be:
var identitySettingsSection = Configuration.GetSection("AppIdentitySettingsConfig");
services.Configure<AppIdentitySettingsConfig>(identitySettingsSection);
or
services.Configure<AppIdentitySettingsConfig>(options => Configuration.GetSection("AppIdentitySettingsConfig").Bind(options));
Both are working same / fine. It will be looking like this:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppIdentitySettingsConfig>(options => Configuration.GetSection("AppIdentitySettingsConfig").Bind(options));
Important note is make sure the parameter after GetSection is exactly the same as per your config file.
Next are how i set up for the other files.
I have been struggling on this and here is what I found out.
In your webApp project, go to the Startup.cs, go to the method ConfigureServices, and add the following code:
it can be:
var identitySettingsSection = Configuration.GetSection("AppIdentitySettingsConfig");
services.Configure<AppIdentitySettingsConfig>(identitySettingsSection);
or
services.Configure<AppIdentitySettingsConfig>(options => Configuration.GetSection("AppIdentitySettingsConfig").Bind(options));
Both are working same / fine. It will be looking like this:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppIdentitySettingsConfig>(options => Configuration.GetSection("AppIdentitySettingsConfig").Bind(options));
Important note is make sure the parameter after GetSection is exactly the same as per your config file.
Next are how i set up for the other files.
Subscribe to:
Comments (Atom)