Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

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

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

Comments

@daiplusplus
Copy link

daiplusplus 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?

@daiplusplus daiplusplus 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

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

Fixed in 3408287

@lbugnion
Copy link
Owner

Fixed and released in V5.4.1

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

No branches or pull requests

2 participants