Skip to content
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

Breaking change - Open generic types #44

Closed
kakone opened this issue Mar 12, 2018 · 5 comments
Closed

Breaking change - Open generic types #44

kakone opened this issue Mar 12, 2018 · 5 comments

Comments

@kakone
Copy link

kakone commented Mar 12, 2018

Hello,

I have a problem with the changes due to the commit f2bd7d7. In my assembly, I have a class like this :

public class OpenGeneric<T> : IOpenGeneric<T> { }
public interface IOpenGeneric<T> : IOtherInheritance { }
public interface IOtherInheritance { }

When I do .AsImplementedInterfaces(), I now obtain an error (this class was excluded before the changes) : 'Cannot instantiate implementation type 'Scrutor.Tests.OpenGeneric1[T]' for service type 'Scrutor.Tests.IOtherInheritance'.'

So, perhaps it would be nice to have an option to disable autoregistration for open generic types. Otherwise (better option), the IOtherInheritance interface should be excluded from the registration.

@khellang
Copy link
Owner

Ugh. Yeah, I was afraid of this happening, as mentioned in #42 (comment) 😢

Can you tell me a bit more about the scenario you're describing? Those are types from the Scrutor test assembly. Is that really the types you're having trouble with?

Why is it problematic to register the generic class? Is it not meant to be created? Perhaps you can make it an abstract class?

In general, it isn't problematic to register stuff that's never resolved. Why are you resolving the type if you didn't expect it to be registered? If you didn't expect it to be registered, why is it implementing the interface?

I need to think long and hard about what to do here. I don't really want to introduce a myriad of flags to configure the scanning (there's already public/private, and in-/excluding nested types has come up). I'd rather have people tweak their scanning filters. Not including open generic types was an oversight and should've been included from the start.

Maybe I'll let this issue sit here for a bit to see if others are experiencing issues as well. You should still be able to run on v2.1 fine 😊

@khellang
Copy link
Owner

khellang commented Mar 12, 2018

Hmm. After looking at the types again, I think that's a bug 🐛 There should be no way to register an open generic type to a non-generic interface as there would be no way to close the type by resolving through the interface.

@khellang
Copy link
Owner

Ok, I've pushed v2.2.2 to NuGet that will hopefully fix this, but it might take a couple of minutes for it to be indexed.

Wanna try it out and let me know if that fixes it for you?

@kakone
Copy link
Author

kakone commented Mar 13, 2018

Yes, perfect, it fixes my problem.

Thank you very much for the responsiveness (and for sharing this useful project).

@kakone kakone closed this as completed Mar 13, 2018
@khellang
Copy link
Owner

Thank you for confirming the fix 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants