Simplified Creation Patterns

Simplified Creation Patterns

Repository Factory

We wanted to provide a simple way to construct both domain repositories and simple Repositories. This lead us to create two different factories for repository. We ship a default factory for both of these, but we also ship interfaces for these as a test and extension point.

Repository Factory

This allows you to construct a simple repository that doesn’t need any of the DomainRepository features.

1
2
3
4
5
6
7
8
     public interface IRepositoryFactory
    {
        /// <summary>
        /// Creates a repository for the requested domain
        /// </summary>
        /// <returns>Domain specific repository</returns>
        IRepository Create();
    }

Domain Repository Factory

This allows you construct a repository specific to any domain that the factory is dependent on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public interface IDomainRepositoryFactory
{

    /// <summary>
    /// Creates a repository for the specified <see cref="IDomain"/>
    /// </summary>
    /// <typeparam name="T">Domain for repository</typeparam>
    /// <returns><see cref="IRepository"/></returns>
    IRepository Create<T>() where T : class, IDomain;

    /// <summary>
    /// Creates a repository for the specified <see cref="IDomain"/>
    /// </summary>
    /// <param name="T">Domain for repository</param>
    /// <returns><see cref="IRepository"/></returns>
    IRepository Create(Type type);
}

Comments