I'm in the process of migrating a medium-sized AR/MonoRail project
from the "ActiveRecord" pattern (using the static Find/FindAll/etc...)
to a repository pattern.  It's a big task (and taking a long time
since it's a side project), but the app started small and now that
it's medium sized (and growing), I really need to have more automated
unit tests and those just aren't possible using the static methods.
I'm also moving away from inheriting from ActiveRecordBase<T> and
using the ActiveRecordMediator<T> in my repositories.

Going forward, if I was starting a new project with ActiveRecord, I
would stick with the repository pattern and ActiveRecordMediator +
POCO's (Plain Old CLR Objects).  It's cleaner and gives more
flexibility to your data architecture and makes testing/mocking much
easier.

---
Patrick Steele
http://weblogs.asp.net/psteele



On Fri, Jul 30, 2010 at 8:06 AM, Paul Bijl <[email protected]> wrote:
> Hi,
>
> I'm writing this post because I'm getting pretty confused about a good
> way to use ActiveRecord in my projects. I've been using ActiveRecord
> for some time now in my projects, and I really like it. It's easy to
> use, frees me from writing all kinds of sql queries and allows me to
> rapidly start my projects. At the moment, I work alot with the Asp.Net
> MVC framework, which I also love. I think these two techniques are a
> fine combination.
>
> Lately however, I begin to experience some problems. As my projects
> grow in size, and my knowledge and experience expand, I began to think
> about the right way to use ActiveRecord, and how it should fit in my
> projects 'Architecture'.
>
> At the moment, when I create a project, I create a folder called
> Models, and I put all my ActiveRecord Model Classes in there (for
> example Order). From my MVC-controllers, I call the various static
> methods inside the Models to get objects from the db. (FindAll,
> FindOne, etc). Depending on my needs, I provide some Expressions to
> get specific data. When I got my data, I pass it on to my view, fairly
> simple.
>
> As some of you would point out, this isn't a best practice. I
> sometimes receive the infamous 'No Session' errors, so I began to use
> ViewModels. This all feels quite natural.
>
> The problem is that my current method doesn't feel good anymore. By
> accessing the AR Models directly from my controllers, it feels tightly
> coupled and it seems difficult to UnitTest. So I began to read about
> repositories, data access layers, data access objects and that kind of
> stuff, and I got pretty lost..
>
> Somehow the use of a repository feel natural (its mockable/fakeable,
> and this way my program doesn't really know about my ORM, which makes
> it easy to change to another one), but after reading alot of articles,
> i'm not so sure anymore (like today I read some aricles by Ayende,
> saying this is really a YAGNI-point)
>
> So my question is really: how should I implement AR in my projects,
> and how do YOU implement it? Is it a good or bad practice my
> controllers 'know' about my ORM, should I use Interfaces and
> repositories?
>
> I know there isn't ONE answer to this, and I really know it all
> depends on the type of projects, but I really hope someone can shed
> some light on this problem, show me some examples and help me
> understand better.
>
> Kind regards,
> Paul
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/castle-project-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to