TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Harish Batchu
NA
255
70.2k
How can i access connection string form appsetting.json file
Jun 24 2019 12:58 AM
I have connection string in appsettings.json file. I need to access that connection string Class library Project. i done the following code to access connection stirng but still i am getting null.
startup.cs
public
Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public
IConfiguration Configuration {
get
; }
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSingleton<IConfiguration>(Configuration);
}
In class library project
protected
string
ConnectionString;
protected
int
CommandTimeout;
private
IConfiguration _config;
#endregion
public
Database(IConfiguration configuration)
{
_config = configuration;
}
#region Constructor
public
Database()
{
ConnectionString = _config.GetConnectionString(
"DefaultConnection"
);
CommandTimeout = 60;
}
Please give me solution for this ASAP
and i gone through the below link
https://stackoverflow.com/questions/51304432/how-to-read-connection-string-inside-net-standard-class-library-project-from-as
but i could not understand to inject the connection stings
Reply
Answers (
6
)
Requirement for building intermediate API for Angular/java
Websocket in MVC