dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Is it possible to read System.Type from an appsettings.json file in a .net core application #1898

Closed AnithaLingam closed 6 years ago

AnithaLingam commented 7 years ago

In my project i need to read the System.Type setting from appsettings.jason..but not able to read please look in to this .

Here is my code: appsettings.jason: "LogKafkaFactoryConfiguration": { "type": "SPGMI.Logging.NetCore.Kafka.Configuration.LogRdKafkaClientFactory, SPGMI.Logging.NetCore" },

I want to read type and pass to below method..below code in .Net 452 _clientfactory = System.Activator.CreateInstance(LogConfiguration.GetInstance().Client.type) as IFactory;

Samething needs to be odne .net core..

davidfowl commented 7 years ago

What's the problem? Which part of the code are you looking for?

AnithaLingam commented 7 years ago

Hi, My appsettings.jason has a setting like below..

"LogKafkaFactoryConfiguration": { "type": "SPGMI.Logging.NetCore.Kafka.Configuration.LogRdKafkaClientFactory, SPGMI.Logging.NetCore" },

I need to read this type setting ..and my class looks like below but I am able to read the setting to string only.. but I want the ‘Type’ because I need to use System.Activator.CreateInstance(LogKafkaFactoryConfiguration.type) in parent class.

Public class LogKafkaFactoryConfiguration { public string type { get; set; } }

Please help. From: David Fowler [mailto:notifications@github.com] Sent: Monday, January 09, 2017 12:56 PM To: aspnet/Home Cc: Lingam, Anitha; Author Subject: Re: [aspnet/Home] Is it possible to read System.Type from an appsettings.json file in a .net core application (#1898)

What's the problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/aspnet/Home/issues/1898#issuecomment-271223473, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATszvYDIc9N_WYv2KU66ojXrN8trEm5Vks5rQeD0gaJpZM4Ld-ck.


The information contained in this message is intended only for the recipient, and may be a confidential attorney-client communication or may otherwise be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, please be aware that any dissemination or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify us by replying to the message and deleting it from your computer. S&P Global Inc. reserves the right, subject to applicable local law, to monitor, review and process the content of any electronic message or information sent to or from S&P Global Inc. e-mail addresses without informing the sender or recipient of the message. By sending electronic message or information to S&P Global Inc. e-mail addresses you, as the sender, are consenting to S&P Global Inc. processing any of your personal data therein.

aspnet-hello commented 6 years ago

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.