473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use repository pattern in Asp.net mvc?

83 64KB
How to use repository pattern in Asp.net mvc?
Oct 28 '20 #1
2 3510
SwissProgrammer
220 128KB
There is a convoluted article about that [here].

Please be more specific in your question please.

If you cannot be specific in detail, then tell us what you are trying to do and give us some of your thoughts on the difficulties that you are encountering.

Thank you.
Oct 29 '20 #2
Frinavale
9,735 Expert Mod 8TB
The idea behind this pattern is really to create an abstract layer between your classes and their data-store (the place(s) where their data is persisted).

Essentially, your class needs to be able to persist data in a repository somewhere...maybe it's stored in a SQL database, or CSV file, or XML file...or maybe the data is stored in multiple places and needs to be aggregated together for your class's repository.

The details around actually maintaining that repository of data should not be the responsible of your Models/Entity/Base-Business-Layer-Class. The reasoning behind this is because once you start bleeding repository storage specifics into your base-classes, you cross layers and create a binding that can lead to problems in testing and/or force your class to be designed around how it's data is stored (which is not desirable).

Instead, you create an abstract interface that provides methods to server as the repository. This interface is defined in your application's base business logic layer but the implementation of the interface is done in your data access layer. This means that your business logic layer can implement the necessary methods/functions to carry out what it requires to work, but leaves the actual database work to the data access layer.

The implementation of the interface in the data access layer will take care of the specifics required for the repository. It's the implementation of the interface that does the work of getting/storing the data (which may be collected from multiple places, like your own database, an API call to a web service, and/or an external database from another system).

The benefit of abstracting the repository is that the implementation of the interface may be specific for testing purposes; wherein, the data returned by the implementation is known by the test code so that the business logic and classes can be tested for expected results. The two implementations (or more) can be swapped out depending on your needs.

The article linked in SwissProgrammer's post should be helpful to you.
Nov 2 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: games60 | last post by:
Hi, I have a xml file and i want to make the repository of it so that i can fire queries on it to extract the data i need from the XML file. Does anyone know how to make the XML repository....
2
by: E.T. Grey | last post by:
Hi, I am using CVS as my file repository for some VC projects. Does any one know which of the solution related files I need to store: i.e., do I need to store the files with these...
0
by: yenlin.liu | last post by:
Who is the owner of the ebXML Registry Repository? Since The ebXML Registry Repository stores many business profiles and business scenarios. Companies can upload/download data from the ebXML RR....
2
by: Lars | last post by:
Hello, Anynoby knows a content repository similar to Content Repository for Java? I want to use a content repository without dependency of the storage system. I want to use file system or...
11
by: HMS Surprise | last post by:
Greetings, Could someone point my muddled head at a/the python repository. I know that one exists but cannot find it again. In particular I am looking for a standalone search tool that given a...
4
by: rahatekarabhijeet | last post by:
Hi, I have seen that some modules which are available on CPAN are not listed in ActiveState repository. So those are not available to install by using ppm. I find out the way of adding adding...
0
vikramadith
by: vikramadith | last post by:
I am new to patterns, so give me a hand here please. :D I am writing repository classes, and some of my GetSomething() methods will undoubtedly take a long time to complete. We will need to run...
0
by: gangadhar125 | last post by:
Hi I've created a repository named as allProj at server. allProj structure is as follows: allProj - Projects - projectA - projectB - projectC - projectD
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.