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

 

Repository Factory and Enterprise Library Configuration GUI Designer


I mentioned the new Repository Factory from Microsoft Patterns & Practice Team, which is a replacement / ehancement to the Data Access Guidance Package.

One of the new features on the RepositoryFactory is the use of the App.config and Web.config files to store Repository Class information. Below is a snippet of the configuration file that shows the ICustomerRepository Interface mapped to the CustomerRepository concrete class:

 

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

 

Using the RepositoryFactory Class one can then get a concrete instance of ICustomerRepository:

 

class Program
{
   
static void Main(string
[] args)
    {
        ICustomerRepository repository
=

            RepositoryFactory.Create
<ICustomerRepository>();

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

 

Very cool.

For kicks I decided to add GUI Design Support in Enterprise Library so I could see and manipulate the list of repositories from within the Enterprise Library Configuration Editor. After a couple of hours GUI design support for the Repository Factory was born:

 

Repository Factory and Enterprise Library GUI Support

 

You can see the new nodes in Enterprise Library- Repository Factory, Repositories, and then a list of the Repositories you have in the configuration file.

You can see the details in the Properties Window. Notice that I now also have support for EnvironmentalOverrides for specifying different repositories for different environments!

 

Repository Factory in Enterprise Library

 

I could have use the Type Selector in Enterprise Library to choose the InterfaceType and RepositoryType, but the Type Selector in Enterprise Library is not as useful as I would like as it lists every type available in all assemblies as opposed to allowing me to apply a filter. Therefore, InterfaceType and RepositoryType are displayed as strings which has the drawback of being mistyped but the the pro of being easy to use via copy and paste :)

The code is not as bad as one might think to pull off Enterprise Library GUI Design-Type Support:

 

Repository Factory Design

 

I thought the developers on the Repository Factory Development Team might like the code, so I kept to their namespaces, etc.

So, all in all, I am pretty happy with the first cut. It shows off the ability to get the Enterprise Library Configuration Tool to support custom configuration sections for easier design time support.


Tags: EntLibConfigurationEditor


Topics



 

Popular Tags



Recent Links