Open jdh28 opened 1 month ago
Yeah, a ton has changed since 4.9.2 was released back in early 2019. I also know ACTNARS has been no end of trouble, like registration order matters with it and it provides a lot of weird exceptions by effectively registering everything in the system. Basically.
I'm not sure we'll be able to "hop right on this." We'd love to see a PR for it, though.
I have had a look at this, but I'm struggling to understand the root cause. Just in case it is helpful to anyone who looks at this in the future, this is what I have discovered so far.
I reduced my test case further - the failure can be observed resolving what I called 'ExternalDependency' above directly.
[Fact]
public void IgnoresRegisteredInstancesWithInternalCtorWhenResolvingFromScope()
{
// issue 1433
var cb = new ContainerBuilder();
var internalCtor = new TypeWithInternalCtor();
cb.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
var container = cb.Build();
using var scope = container.BeginLifetimeScope("scope1", b => b.RegisterInstance(internalCtor));
var resolved = scope.Resolve<TypeWithInternalCtor>();
Assert.Same(internalCtor, resolved);
}
TypeWithInternalCtor
in GetInitializedServiceInfo()
.BeginServiceInfoInitialization
the ExternalRegistryServiceMiddlewareSource
wraps the root container, not the lifetime scope so any registrations ignore the scope.GetInitializedServiceInfo()
, but now in the root container, not the scope.GetInitializedServiceInfo()
we iterate through the available sources, which includes ACTNARS.My best bet may be to explore getting rid of our need for using ACTNARS. It was probably very originally used out of laziness...
Describe the Bug
I have an object instance that I'm providing when creating a lifetime scope. The type's constructor is internal. When trying to resolve a component that depends on this type, I get an exception because the type has no public constructors. However, an instance of the type has been provided so there should be no need to examine its constructors.
The AnyConcreteTypeNotAlreadyRegisteredSource source needs to be registered to trigger this.
Interestingly, if you don't use a scope and do all the registrations in the container root, then the resolve succeeds.
I've encountered this issue upgrading a large application from v4.9.2 to v8.1.0. The change in behaviour started in v6.0.
Steps to Reproduce
Expected Behavior
The call to Resolve to succeed and the instance of Service1 to be created with the instance of ExternalDependency passed into its constructor.
Exception with Stack Trace