Q:

Is it possible to access an non-static object in the C# REST API controller?

Is it possible to access an non-static object in the C# REST API controller?
For description:
I want to program a REST-API for an project. The data comes from a database. But I dont want do ask the database every time a request is triggered. So I have an Object "gen" that talks to the database and buffers the result.
I create the object direct from start and it holds itself alive and refreshes his internal data.
But how can I give the object to the REST-Controller (ValuesController) ?
I dont want to create the object every time someone wants new data.
Examplecode:
namespace GenAPI
{
    public class Program
    {
        public static void Main(string[] args)
        {
            GenAPI gen = new GenAPI(); // gen.table is the object of intrest

            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args)
        {
            var wh = WebHost.CreateDefaultBuilder(args);
            wh.UseUrls("http://*:4999");
            wh.UseSetting("windowsAuthentication", "false");
            wh.UseSetting("anonymousAuthentication", "true");

            var iwh = wh.UseStartup<Startup>().Build();

            return iwh;
        }
    }

    public class Startup
    {
        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(); }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
            if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();

            app.UseMvc();
        }
    }
}

namespace GenAPI.Controllers
{
    [Route("")]
    public class ValuesController : Controller
    {      

        //[HttpGet]
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        [HttpGet("{url}")]
        public IEnumerable<string> Get(string url)
        {
            List<string> result = new List<string>();

            //foreach (var r in gen.table.Rows)        // <-- Here I want do get the data 
            //    result.Add(r[0]);

            return result;
        }

        [HttpPost]
        public void Post([FromBody]string value)
        {
        }

        [HttpPut("{id}")]
        public void Put(int id, [FromBody]string value)
        {
        }

        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}

A:

We had the same requirement and what we did was create a Global class with a static property that was the cached data:
public class Global
{
    private static CacheObject _cache;
    public static CacheObject cacheObject
    {
        get
        {
            if(_cache == null)
            {
                InitializeCacheObject();
            }
            return _cache;
        }
        set
        {
            _cache=Value;
        }
    }
    public void InitializeCacheObject()
    {
        //get your data from db
        CacheObject = db.getData();
    }
}

in your controller, you can do this:
var model = Global.CacheObject.Rows.ToList();

