3

Just started a 'real world' project using .NET MVC, Ninject, PetaPoco and plan to use the repository pattern.

I used the PetaPoco T4 template w/ 'GenerateOperations', 'GeneratePocos', and 'GenerateCommon' all = true. Looking at the generated code, it seems to make sense to extract the 'Record' class into a generic repository interface and/or class, but I haven't been able to wrap my head around how to go about it.

With my limited DI knowledge, it also seems to make sense to tie the 'GetInstance' piece into Ninject somehow on a 'per-request' basis - but how should I go about it?

In case it isn't apparent already, I'm a newbie to DI, the repository pattern and PetaPoco. :)

seekay
  • 2,493
  • 3
  • 27
  • 33

2 Answers2

2

I spent a long time over thinking the repo pattern, in the end I decided simple is best..

The Repo I posted on my blog is not yet complete, but it will give you a good start ( I have made changes since that post.. if you want them I can zip something up).

I was a little restricted in my implimentation as I was moving from another DA so had to make my PetaPoco repo work in the same way as my previously defined patern.. but it works and thats what the repository patterns all about.

I'm afraid I'm just learning DI myself so Im not able to help you with that at the moment.

David McLean
  • 1,462
  • 1
  • 12
  • 27
  • Dave, first of all, thanks for that blog post - it helps big time! If you could put a zip together that would be really great. I'm trying to hard to not over-engineer, and trying to find other samples/examples that are not just a demo aren't that easy :) – seekay Sep 08 '11 at 15:41
  • I will create a follow up post over the weekend and put a zip together. Would do it today but I'm stacked. – David McLean Sep 09 '11 at 08:20
  • Thanks - looking forward to it! I still haven't gotten it work w/ Ninject but putting that aside for now. Will revert back and update this question once I make some progress. – seekay Sep 09 '11 at 22:50
  • have added IRepository and PetaPocoRepository into a rar and you can grab them here -> http://programmerdave.com/petapoco-repository-zipped-code/ – David McLean Sep 11 '11 at 21:38
0

Check out this guys blog post - he's doing exactly what you want as far as setting up a repository pattern with petapoco.

With regards to setting up MVC3 + Ninject + Repositories, its answered in this question.

On a recent project I've been using asp.net mvc3, autofac and petapoco - using the repository pattern with out a worry.

Community
  • 1
  • 1
brodie
  • 5,354
  • 4
  • 33
  • 28
  • thanks. I'd seen that post earlier but forgotten about it. It does do what I need, but it seems that all possible methods have been dumped in the PocoRepository, whereas I'd be more comfortable adding model-specific repositories, and possibly using [transactions via an ActionFilter](http://bit.ly/pOl5QS). I am curious, however, about what's in that ConnectionStringDB class. For now, I guess I need to try his approach out my way and see if it works with my changes (I may be over-thinking this). Thanks! – seekay Sep 08 '11 at 06:38