The Full Stack, Part 5: Implementing the repository with EF Code First and Dependency Injection

Play The Full Stack, Part 5: Implementing the repository with EF Code First and Dependency Injection

The Discussion

  • User profile image

    Thank you guys. The Full Stack is great! Smiley

  • User profile image

    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.


  • User profile image
    Bob Cravens

    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?

  • User profile image

    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.

  • User profile image

    @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.

Add Your 2 Cents