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

SimpleIoc.Register does not enforce generic type TClass: TInterface constraint #5

Closed
Jehoel opened this issue Nov 3, 2017 · 3 comments
Closed
Assignees
Milestone

Comments

@Jehoel
Copy link

@Jehoel Jehoel commented Nov 3, 2017

SimpleIoc.Register<TInterface,TClass> does not have the generic type constraint that TClass : TInterface.

So you can do this:

class IFoo { }
class Foo : IFoo { }
class Bar {}

SimpleIoc.Register<IFoo,Bar>();

...and you won't get a compiler error, but it will crash at runtime.

I noticed that the Register<TInterface,TClass> method does have where TInterface : class where TClass : class as a constraint, so I suspect this isn't a simple oversight. Is there a reason it doesn't have a TClass : TInterface constraint?

@Jehoel Jehoel changed the title SimpleIoc.Register does not enforce generic type interface constraint SimpleIoc.Register does not enforce generic type TClass: TInterface constraint Nov 3, 2017
@lbugnion
Copy link
Owner

@lbugnion lbugnion commented Nov 25, 2017

That's a good point. I am not 100% sure why I went this way. I will add this to the backlog and look into it.

@lbugnion lbugnion self-assigned this Nov 29, 2017
@lbugnion lbugnion added this to the V5.4.0.2 milestone Nov 29, 2017
lbugnion added a commit that referenced this issue Nov 29, 2017
@lbugnion
Copy link
Owner

@lbugnion lbugnion commented Nov 29, 2017

Fixed in 3408287

@lbugnion
Copy link
Owner

@lbugnion lbugnion commented Feb 12, 2018

Fixed and released in V5.4.1

@lbugnion lbugnion closed this Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants