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

Question: Are Repositories need any longer? #4899

Closed
LorenDorez opened this issue Mar 24, 2016 · 8 comments

Comments

Projects
None yet
5 participants
@LorenDorez
Copy link

commented Mar 24, 2016

I was doing some research and someone pointed out that Line 24 of the DBContext Class states

DbContext is a combination of the Unit Of Work and Repository patterns.

Does this mean that we no longer need to abstract EF to a Repository and then use and Interface to inject it into Controllers?

@rowanmiller

This comment has been minimized.

Copy link
Member

commented Mar 24, 2016

It's really up to you. There are two main reasons you may want to introduce a repository which are not handled by DbContext:

  • Removing any strong coupling between your app logic and data access layer. Though in reality, even with this abstraction it is very difficult to swap out a data access layer unless you build and test for multiple data access technologies right from the start.
  • Constraining the operations that the app layer can perform on the database. DbContext exposes IQueryable so the app can compose any query allowed by LINQ. Repositories that don't return IQueryable can help you control what is sent to the database.

Ultimately it comes down to a philosophical/style/preference decision. Many apps have been built successfully using either approach.

@LorenDorez

This comment has been minimized.

Copy link
Author

commented Mar 24, 2016

@rowanmiller Thanks for the insights. I currently working on a project in which i find my repositories have a lot of methods like FindById, FindByName, FindBy.... and also a lot of dynamicness needed for When to Include and When to OrderBy etc..

I just started research <Expression<Func<>> to handle the dynamic-ness of when to Include certain tables and when not to and came across a lot of article stating there isnt a new for Repos with the new EF7 so figured it was better to go to here any get some insights.

@ilmax

This comment has been minimized.

Copy link
Contributor

commented Mar 24, 2016

No, repository pattern for EF context is evil! Just don't use it!

@findulov

This comment has been minimized.

Copy link

commented Mar 25, 2016

@ilmax I personally prefer using repositories in my data access layer for encapsulating DbContext, so other developers can't use it directly in the application and create repetitive queries. I'd like to hear your point of view why not to use this approach.

@bricelam

This comment has been minimized.

Copy link
Member

commented Mar 25, 2016

FYI, Programmers Stack Exchange is a good place to discuss these types of design questions.

@ilmax

This comment has been minimized.

Copy link
Contributor

commented Mar 25, 2016

@ge6a93 this is not the best place to discuss design, anyway there are a tons of good posts int the wild on this same subject :)

@rowanmiller

This comment has been minimized.

Copy link
Member

commented Mar 25, 2016

Closing this one out as I think we have addressed everything from the EF side.

@LorenDorez

This comment has been minimized.

Copy link
Author

commented Mar 30, 2016

I posted this on Stack Exchange as suggested. I would appreciate the discussion continueing there

http://programmers.stackexchange.com/questions/314266/are-repositories-needed-any-longer-in-asp-net-5-ef7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.