I have .NET CORE 8 + Autofac 8.4.0, no multitenancy. Regular Rest API application.
I have two service registrations like:
builder.RegisterType().As();
builder.RegisterType().Keyed("buzzinga!");
So main idea was to use both - common and keyed registrations.
Then I have the following code somewhere in application:
using (var myScope = _container.BeginLifetimeScope())
{
var service = myScope.Resolve
}
And in that case I expect that SomeService will be resolved. But SomeAlternativeService was resolved instead.
No any keyed assignments/resolving before.
BTW, if I use PreserveExistingDefaults() for the second registrations - no effect (which actually ok because both registrations does not have same level).
How I resolved it: second registration comes first.
In that case inside scope non-keyed registration will be resolved by regular call of Resolve<> method correctly. And in case I need keyed registration - I can use ResolveKeyed<> which will work correctly too.
So my question is - is it correct behavior that two different registrations (keyed and non-keyed) could override each other in case keyed registrations comes after non-keyed regular one?
May be I have wrong understanding, but keyed and non-keyed registrations should be separated and not influence to each other.