skip to the main content area of this page
Patterns and Practices

 

Repository Factory - New and Improved Data Access Guidance Package


The Data Access Guidance Package in the Web Service Software Factory is now a separate Guidance Package called the Repository Factory. It already has a number of cool features that will make it much more enjoyable to use over the previous Data Access Guidance Package. To name a few:

  • Automatic Mapping of Stored Procedure Parameters to Entity Properties
  • Generates an Interface for each Repository Class
  • Generates a RepositoryFactory Class for Retrieving Individual Repositories
  • Repositories Registered via Configuration Section in App.config / Web.config
  • Common and Base Repository Classes in Separate Repository Assembly

Very, very slick!

When you download and register the Repository Factory it looks pretty identical to the Data Access Guidance Package:

 

Repository Factory

If this is unfamiliar to you, check out the Data Access Guidance Package Screencast.

Create Data Access Layer Using Data Access Guidance Package Screencast

The solution generated looks a little different because now all those common and base classes that cluttered up things are now tucked away in a separately assembly:

 

Repository Factory Base Classes

Interfaces are now created for each Repository generated by the Repository Factory:

 

public class CustomerRepository :
Repository
<Customer>, ICustomerRepository

 

with the interfaces being clean and simple:

 

public interface ICustomerRepository
{
    Customer GetCustomersByCustomerId(System.Int32 customerId);
    List<Customer> GetAllFromCustomers();
    void Add(Customer customer);
    void Remove(System.Int32 customerId);
    void Save(Customer customer);
}

 

What makes this really cool is that a new RepositoryFactory Class is generated which allows you to grab your Repositories as follows:

 

class Program
{
    static void Main(string[] args)
    {
        ICustomerRepository repository =
            RepositoryFactory.Create<ICustomerRepository>();

        Customer customer = repository.GetCustomersByCustomerId(1);
    }
}

 

How awesome is that? :)

Also generated by the RepositoryFactory is a configuration section in your configuration file where Repository Classes are registered:

 

<configuration>
  <configSections>
    <section name="repositoryFactory" ... />
  </configSections>
  <repositoryFactory>
    <repositories>
      <add
            interfaceType="...ICustomerRepository..."
            repositoryType="...CustomerRepository..." />
    </repositories>
  </repositoryFactory>
</configuration>

 

Some really nice improvements! Good job guys.

Check out the RepositoryFactory CodePlex Site for more information.


Tags: CodeGeneration, DataAccessLayer, DataAccessGuidancePackage


Topics



 

Popular Tags



Recent Links