-
-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RegisterTypes will attempt to register abstract types (undocumented breaking change in v6.5.0) #1388
Comments
Based on the repro, it seems like the problem has to do with interface types, not abstract types. ( |
Also, reading this through, it seems like - while the behavior is, admittedly, breaking - it's potentially a desired behavior. That is, the repro is saying, "I want to try to register this interface in the container!" and the container, on build, is saying, "Sorry, you can't do that." I know we've seen some questions before with folks wondering why we'd "allow" different behaviors that aren't "legal" or consistent. For example, if you tried to do Does this sound like the issue you're describing? |
The repro behaviour is the same for abstract classes too. The behaviour affects all abstract types which includes interfaces, even though the
Yeah, the undocumented breaking change aspect is definitely the main point here. It caused a lot of unexpected difficulties in a codebase that heavily used scanning registrations over all of the types in certain assemblies, all of which had to be updated to include a |
Let me see if I can figure out whether this was intentional or not so we can determine what to do. |
Looking at the changes, we can see what happened: A lot was shifting around in the effort to centralize reflection type caches (to support So: it was an inadvertent breaking change. Darn it. The question is now to figure out what to do about it. I can absolutely see the desire to be able to pass in an array of whatever types and have the filtering done for you. It makes it easy to throw stuff in and go, and it has reasonable parity with some of the other methods like I can also see the desire to have it work like If we put the filter back, it should have no effect on users who have updated to the more "trimmed" lists of only valid types, so it wouldn't be another breaking change. It may also fix some folks who relied on the old behavior. Hence, while I'm not really interested in encouraging folks to send a raft of bad types in there, I sort of lean a tad toward fixing this up and putting the filter back on. In either case, we should:
Let me tag @alistairjevans to see if he has any additional thoughts. |
Chatted with @alistairjevans and I think we're in agreement this is a bug. I was thinking it'd be nice to keep So the plan of action:
I'll see about getting a PR in for this soon. |
This is going out in 7.1.0 which should be published on NuGet within the next hour. |
Describe the Bug
In Autofac v6.4.0, a scanning registration using
RegisterTypes
that includes types that cannot be constructed (e.g. interfaces, abstract classes) will work fine.In Autofac v6.5.0 onwards, it will attempt to register those non-constructible types resulting in an
Autofac.Core.Activators.Reflection.NoConstructorsFoundException
upon building the container.This is a breaking change that I couldn't find documented anywhere.
Steps to Reproduce
Expected Behavior
No exception, test passes (v6.4.0 behaviour)
Exception with Stack Trace
v6.5.0 onwards throws:
Dependency Versions
Autofac: v6.5.0
Additional Info
A workaround is for the user to filter out abstract types from the types passed to
RegisterTypes
themselves.In trying to figure out why I was getting this exception after upgrading to v6.5.0 from v6.4.0 I took a look at the diff between the two versions, and the removal of
!t.IsAbstract
inCanBeRegistered
in this commit was something that stood out to me that might be the cause.The text was updated successfully, but these errors were encountered: