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
(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
Sivakumar KonetiPosted Jun 25, 2019, 11:59 PM
Ronika JencyPosted Jun 25, 2019, 5:21 AM
Shailesh UkePosted Jun 24, 2019, 5:10 AM
Harish BatchuPosted Jun 24, 2019, 1:59 AM
Sivakumar KonetiPosted Jun 24, 2019, 1:36 AM
Tamal MarickPosted Jun 24, 2019, 1:11 AM