Since the ComponentModelContainer is built after the execution of the AddCacheContext and the registration process in AttributeInspector registers "blind", the net effect is that that ICacheContext is registered twice!
It "works" because when you inject the interface, the "last" instance will be obtained in the current implementation of Microsoft's IServiceProvider. But I don't know if this is an official behavior.
The solution is to remove the definition in appsettings.json.
This issues may apply to other caches (like Arc4u.Caching.Memory.MemoryCache) which is registered selectively in AddCacheContext but is also mentioned in RegisterTypes as "Arc4u.Caching.Memory.MemoryCache, Arc4u.Standard.Caching.Memory".
When the Guidance generates services (including Yarp), it adds the following statement in
Program.cs
:This statement does a
services.TryAddSingleton<ICacheContext, CacheContext>();
.But the following is also added: in
appsettings.json
:Since the
ComponentModelContainer
is built after the execution of theAddCacheContext
and the registration process in AttributeInspector registers "blind", the net effect is that thatICacheContext
is registered twice!It "works" because when you inject the interface, the "last" instance will be obtained in the current implementation of Microsoft's
IServiceProvider
. But I don't know if this is an official behavior.The solution is to remove the definition in
appsettings.json
. This issues may apply to other caches (likeArc4u.Caching.Memory.MemoryCache
) which is registered selectively inAddCacheContext
but is also mentioned inRegisterTypes
as"Arc4u.Caching.Memory.MemoryCache, Arc4u.Standard.Caching.Memory"
.This only applies to back-ends, not front-ends!