I am in .Net 7.0 and in Program.cs we do not have any functions where there is a scope for dependency injection. The code is directly as follow:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyModel;
using WebMarkupMin.AspNetCore7;
using WordPressPCL;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
// Add services to the container.
builder.Services.AddRazorPages();
var emailConfig = builder.Configuration
.GetSection("EmailConfiguration")
.Get<EmailConfiguration>();
builder.Services.AddSingleton(emailConfig);
//builder.Services.AddSitemap();
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
I want to get access to IMemoryCache here and want to store some data in there. How do I do that?
You can do it with something like
Simple working example
Program.cs
ExampleController.cs
You could try it if you want Repo