Wednesday, May 13, 2020

.GetService in Framework and Core

This is in the .NET Framework stuff. This cannot move. There is no HttpConfiguration in .NET Core.

private static void InitAuthorizationCache(HttpConfiguration config)
{
   var cacher = (ICacher)config.DependencyResolver.GetService(typeof(ICacher));
   var logger = (ILogger)config.DependencyResolver.GetService(typeof(ILogger));
   var authorizationCache = new AuthorizationCache(cacher, logger);
   authorizationCache.LoadCache();
}

 
 

Alright, in Startup.cs, of a .NET Core 3.1 application, we can jam what is above, in here:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
   var cacher = (ICacher)app.ApplicationServices.GetService(typeof(ICacher));
   var logger = (ILogger)app.ApplicationServices.GetService(typeof(ILogger));
   var authorizationCache = new AuthorizationCache(cacher, logger);
   authorizationCache.LoadCache();

 
 

                                    

I will not show all of the method immediately above because it eventually has app.UseEndpoints in it, etc. Run the ILogger using using Serilog.

Tuesday, May 12, 2020

app.UseEndpoints

You probably need app.UseEndpoints even if you don't need everything inside. You could maybe leave it blank, and especially if each Controller has...

[ApiController]
[Route("api/[controller]")]

 
 

    

...decorating it. In that scenario have:

app.UseEndpoints(endpoints =>
{
});

Sunday, May 10, 2020

more random from Dungeons and Dragons

The gunk at QMap.pub uses QAnon which have only existed since 2017. Q notifications tell you, the listener, of new QAnon. Vivaldi allows for some interesting combos. It seems right-click, right is back and right-click, left is forward. Migraine headaches, outside of ANY sickness, fled into me last week. Yesterday was the first day without. I think in working from home and having May come there was just too much sunlight. Anyhow, I was offered some blue blocker sunglasses. What is NOT communicated (heavily) is that I just blocked off the window in my bedroom. The girl running the game says that war fog allows her to project one screen and have the rest of the players see the one screen redacted, on a different display.

Friday, May 8, 2020

a bit more on IMemoryCache

Remove an id:

_memoryCache.Remove((object) id);

 
 

Fish out a specific type:

var authItems = _memoryCache.Get<AuthorizationCacheItem>(foo);

get IMemoryCache to work with Autofac

In the setup...

builder.RegisterType<MemoryCache>().As<IMemoryCache>().SingleInstance();

 
 

At a Controller...

private readonly IMemoryCache _memoryCache;
public ServiceController(IMemoryCache memoryCache)
{
   _memoryCache = memoryCache;

 
 

In an action...

var cacheEntry = _memoryCache.GetOrCreate("foo", entry =>
{
   entry.Value = (object)"bar";
   return Task.FromResult((string) entry.Value);
});

 
 

Elsewhere, in a different action...

object cacheEntry = _memoryCache.Get("foo");

Secret Manager Tool

It is the stuff which manages secrets.json per ASP.NET Core 2 and Angular 5 by Valerio De Sanctis.

IMemoryCache Interface

...for .NET Core. It is a thing.

.NET Framework Caching

Assuming at the top of a Controller...

private readonly ICacher _cacher;

 
 

...then...

_cacher.AddtoCache("foo", "bar");

 
 

...then...

var meh = _cacher.GetValue("foo");

 
 

...then...

_cacher.FlushKeys();

 
 

...then...

var deleted = _cacher.DeleteKey(id);

 
 

...then...

var authItems = _cacher.GetValue(CacheItems.AuthorizationItems) as
      AuthorizationCacheItem;

What does the [EnumMember] attribute do in C#?

Meh. It allows that which is serializable to be deserialized as an enum.

using System.Runtime.Serialization;
namespace Ecs.Domain.Health.Web.Models
{
   [DataContract(Name = "mode", Namespace =
         Namespaces.PrtgModelsNamespace)]
   public enum PrtgModeType
   {
      [EnumMember]
      Absolute,
      [EnumMember]
      Difference
   }
}

Wednesday, May 6, 2020

Microsoft.Extensions.Configuration

More random extensions stuff... This may come into play when migrating from .NET Framework to .NET Core.

Tuesday, May 5, 2020

What uses a IComponentRegistryBuilder?

This is Autofac stuff. I found a library online that has ComponentRegistryBuilder implementing both IDisposable and IComponentRegistryBuilder. I'd stop now, but I wanted to mention that this was inside:

public event EventHandler<ComponentRegisteredEventArgs> Registered
{
   add
   {
      lock (_synchRoot)
      {
         Properties["x"] = GetRegistered() + value;
      }
   }
   
   remove
   {
      lock (_synchRoot)
      {
         Properties["x"] = GetRegistered() - value;
      }
   }
}

 
 

At the top of the file, _synchRoot is defined like so:

private readonly object _synchRoot = new object();

Saturday, May 2, 2020

zone/NgZone in Angular

This shows up on page 468 of ASP.NET Core 2 and Angular 5 by Valerio De Sanctis and is explained to be a thread encapsulation for JavaScript in Angular. Whenever something has to be tracked back Angular uses these unseen and you should really roll these out too. When talking in from the outside, use a zone.

Friday, May 1, 2020

System.StackOverflowException

we are doing too much

.Primatives

This requires that System.ServiceModel.Primatives be installed:

var serviceClient = client as ClientBase<FNCEWS40PortType>;

 
 

The thing that is wacky about this is that System.ServiceModel without Primatives may already be installed and System.ServiceModel.Primatives uses the same using statement without the .Primatives on the end.