I have the startup.cs as
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing; using Microsoft.Extensions.PlatformAbstractions; using Microsoft.Framework.Configuration; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; using Microsoft.Framework.Logging.Console; using Microsoft.Extensions; using OpsTools.DataAccess; namespace OpsTools { public class Startup { public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { // Setup configuration sources. var builder = new ConfigurationBuilder() .SetBasePath(appEnv.ApplicationBasePath) .AddJsonFile("config.json") .AddEnvironmentVariables(); Configuration = builder.Build(); var test = Configuration["ASPNET_ENV: Development"]; } public static IConfiguration Configuration { get; set; } // This method gets called by the runtime. public void ConfigureServices(IServiceCollection services) { // Add MVC services to the services container. services.AddMvc(); } // Configure is called after ConfigureServices is called. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.MinimumLevel = LogLevel.Information; loggerFactory.AddConsole(); // Configure the HTTP request pipeline. // Add the following to the request pipeline only in development environment. if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); //app.UseErrorPage(); //Configuration.Set("AuthConfig","auth.debug.config"); //Configuration.Set("installFolder", ""); } else { // Add Error handling middleware which catches all application specific errors and // send the request to the following path or controller action. app.UseExceptionHandler("/Home/Error"); // Configuration.Set("AuthConfig", "auth.config"); } // Add static files to the request pipeline. app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); }); } } }
In another class
public class AniRepository { private string _dbPrefix; private string _connectionString; public AniRepository(string connectionString) { _connectionString = connectionString; _dbPrefix = Startup.Configuration.Get("Database:DbPrefix"); }
I get the error
Error CS1061 'IConfiguration' does not contain a definition for 'Get' and no extension method 'Get' accepting a first argument of type 'IConfiguration' could be found (are you missing a using directive or an assembly reference?)
My project.json file
{"webroot": "wwwroot","version": "1.0.0-rc1-update","dependencies": {"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final","Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final","Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final","Microsoft.AspNet.Mvc": "6.0.0-rc1-final","Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final","Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final","Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final","Microsoft.Extensions.Configuration": "1.0.0-rc1-final","EntityFramework": "6.1.3","jqGridWebApi": "1.1.4","EnyimMemcached": "2.13.0","xunit": "2.2.0-beta1-build3239","Moq": "4.2.1510.2205","NLog": "2.1.0","CryptSharpOfficial": "2.1.0","System.Linq.Dynamic": "1.0.4" },"commands": {"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001","kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5005","ef": "EntityFramework.Commands" },"frameworks": {"dnx451": {"frameworkAssemblies": {"System.configuration": "4.0.0.0","System.Data": "4.0.0.0" },"dnxcore50": { } } },"exclude": ["wwwroot","node_modules","bower_components" ],"publishExclude": ["node_modules","bower_components","**.xproj","**.user","**.vspscc" ],"scripts": {"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ] },"configurations": {"Staging": { } } }
Anyway I want to use "1.0.0-rc1-update".