GenericRepository is a project mainly written in C#, based on the View license.
A generic repository pattern implementation for .NET
The intention is to provide a generic repository implementation for many of the common ORMs. This provides a 'normalized' interface to the persistence layer. This 'normalization' has costs and benefits.
The following implementatons exist (others are on their way):
If you want to supply an implementation for an ORM please let me know.
// Create an instance of the session factory. This is typically done
// once and cached. DbSessionFactory is a concrete implementation
// of IDbSessionFactory using a variety of ORMs (e.g. NHibernate,
// EF...etc).
//
// Assembly that contains the NHibernate mapping files. This assembly can contain
// just mapping files. In that case add a class called 'Handle' to do reflection.
//
Assembly resources = Assembly.GetAssembly(typeof(NHibernate.Maps.Handle));
// Create the session factory.
//
IDbSessionFactory dbSessionFactory = new DbSessionFactory(connectionString, resources);
// When necessary...
//
// Create a session. This represents a database transaction.
//
using( IDbSesseion session = dbSessionFactory.Create())
{
// Create a repository.
//
IKeyedRepository<Guid, Person> repo = session.CreateKeyedRepository<Guid, Person>();
// Perform actions on the repository
//
Person person = new Person {Id = Guid.NewGuid(), FirstName = "Bob", LastName = "Cravens" };
repo.Add(person);
// Commit the transaction.
//
session.Commit();
}
To get started do the following:
Infrastructure
project. These interfaces are the abstraction that you will use in your code. Recommended order: IDbSessionFactory
IDbSession
Repository
IReadOnlyRepository
IKeyed
IKeyedRepository
IKeyedReadOnlyRepository
If you have improvements, questions or suggestions please feel free to contact me.
Bob