✅ Is it possible to convert a generic interface to a generic interface?
I'm trying to prevent the creation of multiple giant switches in a controller by passing the instantiation of the interfaces to a factory. Person is the parent class(model) and all the other ones are sub-classes that have no problem to convert to the parent class in another factory. Is this error appearing because it is impossible to convert interfaces?
11 Replies
And here I thought generic repositories were useless complexity. Now we have whole-ass generic repository factories lmao
In any case, see if adding an
out
modifier on the generic parameter helps
As in, interface IPersonRepository<out T>
That, or use an explicit cast like the error says
(Also, you can reduce the code amount by a fair bit by using the hint VS shows you on switch. It'll convert the switch statement into switch expression)when I try to use explicit cast I get this error when trying to use the controller
and with "out" this appears
will have to look more into the switch expression tho
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
I see
I am using EF in DataContextEF but it's probably not optimal and I still have to add the FK since now the entities only have the PK connections.
I will prob try with extension methods as you said, will have to learn more about them
TY for the lengthy advice there is an automatic way to connect the DB with the entities but I was not able to do it initially so just built the context class by hand
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View
I don't quite understand
where in here am I gona use T
?
or should it be inserted in the RepositoryFactory?
Unknown User•11mo ago
Message Not Public
Sign In & Join Server To View