Solved

Persistence ignorance?

Posted on 2011-03-25
7
468 Views
Last Modified: 2012-05-11
Please define it if possible is a few sentences. I can not find a link that does it without a very long start to the answer.

I work in the MVC3 ASP.NET 4.0 world.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:jesusaflores
ID: 35217503
what the problemA??, i don't understand...
0
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 500 total points
ID: 35217506
I'm not sure what the context is for your question, but persistence describes how your data is stored. A beginner coder might fetch data directly from the controller with queries that are specific to the storage, whether it's SQL, XML, etc. By using the repository pattern, you'd introduce a persistance specific repository that knows about the data implementation (SQL, XML, etc.) and hide that detail from the calling controller (or better yet, a service that is called by the controller).
0
 

Author Comment

by:newbieweb
ID: 35217572
I use a Data Dtore around my Entity Framework 4.0 object. I also have my Controller create a new instance on creation then each Controller Action passes that Data Store into each object that's created, and passed in as a parameter to the nth degree, as a parameter in contruction of my classes.

Is this Persistence Ignorance?

I am trying to get my definition of the tem down.

Thanks.
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 500 total points
ID: 35217614
I haven't worked with EF, but if you've got the controllers passing EF objects, then it is most certainly NOT persistence ignorant. The controller should not know anything about how data is manipulated. It should call a service, asking for an entity or a collection of entities. The service would then call the correct repository, in the case EF. You might first develop that app with an XML repository and then convert over to an EF repository. If you had coded the EF specific logic into the controllers, then you'd have to rewrite theme ach time you wanted to switch. The mentioned solution would allow you to hand one or the other repository over to the service, asking it to perform the operation. You can also look into "dependency injection", which MVC 3 supports. You tell the service to accept a repository by way of an interface and then configure a special class to return the appropriate repository when it sees any object looking for an IMyRepository.
0
 

Author Comment

by:newbieweb
ID: 35217809
Interesting. I think you're right. I made it persitence aware.

I did this since saving a Project object to a different instance than the one from which is was called created problems.  I actually have a code change that I could keep, even if I were to remove any Controller awareness of the Data Store.

What I do is:
1) Instantiate a Data Store
2) Retrieve a Project from it
3) Set the Data Store property on the Project
4) When I save that Project, it uses the Data Store which spawned it

Is this logical?

Otherwise, EF makes you go throgh hoops to update an existing object.

0
 
LVL 16

Assisted Solution

by:ToddBeaulieu
ToddBeaulieu earned 500 total points
ID: 35217996
Hmmm . Like I said, I haven't used EF yet, but I'll take a stab.

What's a project in your context? An entity?

I really can't believe EF would want you to return EF specific objects to the controller, embedded in the entities.

I'd expect you to have a service that is handed the entity and asked to save it. The service would then forward the request to the EF repository.

Big guess here .. not sure what the DataStore is, but could it be static, meaning it persists across calls, handling all data operations?
0
 

Author Closing Comment

by:newbieweb
ID: 35218036
Sorry for the confusion. A Project is just an object based on the project class. Thanks.
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question