You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.
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?
The text was updated successfully, but these errors were encountered:
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
SimpleIoc.Register<TInterface,TClass>
does not have the generic type constraint thatTClass : TInterface
.So you can do this:
...and you won't get a compiler error, but it will crash at runtime.
I noticed that the
Register<TInterface,TClass>
method does havewhere 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 aTClass : TInterface
constraint?The text was updated successfully, but these errors were encountered: