Repository Registry

Jul 21, 2010 at 3:24 PM
Edited Jul 21, 2010 at 3:26 PM

This may be outside the scope of a question on MvcTurbine, but I thought I'd try asking anyway.

Our application previously employed poor man's dependency injection, by instantiating the service layer classes in the controllers' constructors, and instantiating repository classes into the service layer classes' constructors. Our design employs several repository classes, where we load data into POCO objects from SubSonic classes.

We converted the injection of the service layer classes into the controllers using MvcTurbine, and we now have a service registry file. I think the idea now, is to do the same for the repository layer. So, do I simply add the repository interfaces to the Service Registry? Or, can we set up a separate registry for the repository layer classes, which would be less confusing? Or, is there a better way to handle the repositories entirely?

And I suppose I should mention, the controllers, service layer classes, and repositories are all in separate projects.

 

Coordinator
Jul 21, 2010 at 3:54 PM
There's several ways you can do this, it's completely up to you: 1 - Do as you say, create a RepositoryRegistration class within the assembly where the contract (interface) and implementations of the registry live. However, this adds a dependency on MvcTurbine.dll for that assembly, so it's up to you if you're OK with that link. 2 - Do the same as #1, however the RepositoryRegistration class lives in a "link assembly" that sole purpose is to link the assembly where your repositories live and MvcTurbine.dll Since Turbine scans all assemblies on the bin folder and process known types (such as IServiceRegistration), the RepositoryRegistratoin class would get picked up and processed. Thoughts?
Jul 21, 2010 at 4:44 PM
The second way makes the most sense to me, as it puts the registration right in the Web site, in the same folder as ServiceRegistration, where it's easily assessible. Is there a conventional way to set up another class, like ServiceRegistration, named RepositoryRegistration, in the same project?
Coordinator
Jul 21, 2010 at 4:52 PM
Ok, I'm confused.... If you're asking to create a new class called RepositoryRegistration, yes, that's totally fine; Turbine will find the class and process any registrations that it provides. As for where does the class live (containing assembly), that's completely up to you. Is this making sense?
Jul 21, 2010 at 8:23 PM
Sorry for the confusion. I was thinking I couldn't have two registrations in the same project. Are you saying that I create a new class called RepositoryRegistration, inherit from IServiceRegistration, create a method called Register(IServiceLocator locator), or is more complicated than that? If it isn't, the problem is that I was trying to complicate it further, something I tend to do with MVC. :)
Coordinator
Jul 21, 2010 at 8:43 PM
No worries :) You can have as many classes that implement IServiceRegistration as you want, there's no limit :) Here's an example - http://gist.github.com/485099