Simon
AddMemoryCache() lifecycle
Hi, I have an AzureWebJob which spins up new instances of a transient class to do work on a schedule. I'm looking at adding some caching, but I want the cache scoped to the instance of the transient class (a new cache each time). As far as I can tell, the AddMemoryCache() invokes:
services.TryAdd(ServiceDescriptor.Singleton<IMemoryCache, MemoryCache>());
and thereofre it's going to give me the same MemoryCache instance forever. Given this, should I bother using DI at all? Should I just create a new MemoryCache instance in my class that needs the cache? Should I manually add the MemoryCache as a transient instead of singleton?1 replies
❔ Fire and forget, do I need a new logger?
I'm working on a small fire & forget background task initiated from asp.net. Essentially following this: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/best-practices?view=aspnetcore-6.0#do-not-capture-services-injected-into-the-controllers-on-background-threads
I am creating a new scope & requesting a new dbcontext.
The question I have is: I want to do some logging as well, do I need to request a new ILogger/ILoggerFactory from the
scope.ServiceProvider
or can I use the ILogger that is DI'd to the Controller?3 replies
❔ update packages for current .net
Is anyone aware of a quick way to update all packages that are tied to the current .net version? For example, my solution/projects are all using .net 6, however VS suggests I update a bunch of packages to the v7.0.0 version (ex: Microsoft.Extensions.Logging.Abstractions) or does this not matter and I should update to v7.0.0 even though I'm on .net 6?
21 replies