Timeline for Does a 'leaky' repository implementation defeat the point of a repository?
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 2, 2019 at 14:11 | comment | added | Mr Cochese | To be honest, EF already uses repository pattern, and wrapping it in another layer of repository pattern just to abstract the data layer even more is almost certainly over-engineering. There’s a competing school of thought that you should just embrace your ORM in the application design. | |
Mar 28, 2019 at 20:13 | answer | added | async | timeline score: 3 | |
Mar 28, 2019 at 19:01 | comment | added | Eric King | Yeah, something like that. It can be an Interface too. See Constraints on Type Parameters | |
Mar 28, 2019 at 18:58 | comment | added | Jez |
So, what, you'd define an empty 'DtoBase' class in your repository project which all your repository DTOs extend, and say where TEntity : DtoBase ?
|
|
Mar 28, 2019 at 18:57 | comment | added | Eric King |
Well, the way it's written where TEntity : class explicitly allows TEntity to represent any class, including EF classes or POCOs or whatever. If you want to limit what kind of class is handled by the interface, change it to where TEntity : somethingelse
|
|
Mar 28, 2019 at 18:55 | comment | added | Jez | Presumably there'd be no way to design the interface to prevent it passing EF entities back and forth? Therefore it would be possible to implement this interface with a class that was supposed to take EF entities, or even domain objects, and DTOs? | |
Mar 28, 2019 at 18:52 | comment | added | Eric King |
The lambda point is also not an EF thing... LINQ is independent of EF and is used in many places that have nothing to do with EF. Try this: replace the arbitrarily named TEntity in your code example with just T . The functionality would not change, but it would be clearer that the IRepository interface is generic and not EF-specific at all. Now, if you are just going to use it to pass EF entities back and forth, that's a different issue. But the IRepository interface itself is agnostic of what kind of class T is, and doesn't leak actual implementation details that I can see.
|
|
Mar 28, 2019 at 18:45 | comment | added | Jez | Well OK on that point. Although in his actual implementation he does just pass EF entities through to EF, suggesting that was his thinking. Also, my point about the lambda stands. | |
Mar 28, 2019 at 18:36 | comment | added | Eric King |
Other than the fact that TEntity has the word 'Entity' in it, what makes you feel that Entity Framework details are being leaked here? The way the code is written, TEntity can be any class, and implementors of IRepository can use any data access mechanism they want; it doesn't have to be EF.
|
|
Mar 28, 2019 at 18:22 | history | asked | Jez | CC BY-SA 4.0 |