The Full Stack, Part 5: Implementing the repository with EF Code First and Dependency Injection
- Posted: Dec 27, 2010 at 4:49 PM
- 12,095 Views
- 5 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- High Quality WMV (PC, Xbox, MCE)
- MP3 (Audio only)
- Mid Quality WMV (Lo-band, Mobile)
- High Quality MP4 (iPad, PC)
- MP4 (iPod, Zune HD)
In this episode, Jon moves converts the previous data access code to use the Repository pattern, looking at some new features in Entity Framework 4 CTP 5 which make this a lot easier. Then we wrap up by using Dependency Injection using Ninject and MVC 3's new support for service location.
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Thank you guys. The Full Stack is great!
2 repositories? Doesn't that waste time testing the fake repository as you can create bugs in the real one? Why not just pass in a context to assign to a local context interface variable so that you can have one repository that handles everything to test once? The benefit also is that you can have multiple data sources; test data, development data (great for design and debug time in WPF & SilverLight) and run time data contexts. It also makes the controller explaination simplier as you still have a context but it's now the repository that is doing the work so that you can use the same code in multiple places and test only once.
Another code smell "db.People.Find(", what ever happened to DRY (Don't Repeat Yourself!) How about for Exits:
var person = this.Rerieve(id);
return person != null;
Why are you using IEnumerable<Person> and not IList<Person>? Wouldn't you end up converting it later anyway in most cases?
Back to the repository thing, I see further on that you use dependency injection and I suppose that creating a gateway to assign the right context to Ninject to supply both a context and a repository might be over kill but I think that is still better than 2 repositories when someone is creating a real application in the long run. Learning the right way first is easier than unlearning the wrong way later is what I say.
This was a good episode as it gets to the meat of design and development.
Great work guys. As someone already mentioned, this episode gets into a lot of the architecture choices that lead to a maintainable solution. A few questions that maybe you can answer:
1. Why not create a generic repository that is used to implement the PersonRepository? Seems like you have a very specific repository that can only be used to manage Person entities. A little bit of generics and you can write that code once. It can then be reused to manage other entities. I know that you currently don't have any other entities, but it seems worth the effort. Thoughts?
2. At the end dependency inject was introduced...go Ninject! Time was spent cleaning up the repository dependency in the controller. What about the context dependency in the repository? I think there is value in letting Ninject wire all that up for you. What do you guys think?
Bob
Unfortunately I cant watch the videos. They say my browser doesnt support HTML5 or silverlight, but im using IE9 and have the current Silverlight version installed. Hopefully smn will figure this out because I'm really interested what they have to say about the subject.
@Sikter: I can't use Silverlight either (for some reason I get no sound). Try one of the Download links on the right - works great for me.
Remove this comment
Remove this thread
close