Solved

Persistence ignorance?

Posted on 2011-03-25
7
465 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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