Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
Created January 4, 2013 11:47
Show Gist options
  • Select an option

  • Save ChrisMcKee/4452028 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisMcKee/4452028 to your computer and use it in GitHub Desktop.
Repository Factory Interface / Implementation (using ninject/nhibernate)
namespace Core.Repository
{
using Core.Model;
using Core.Model.Some;
public interface IRepositoryFactory
{
ISomeRepository SomeRepository();
IRepository<SomeObjectType> SomeObjectTypeRepository();
IRepository<T> Repository<T>() where T : class;
}
}
namespace Data.Repository
{
using Core.Model;
using Core.Model.Some;
using Core.Repository;
using Ninject;
public class RepositoryFactory : IRepositoryFactory
{
private readonly IKernel _kernel;
public RepositoryFactory(IKernel kernel)
{
_kernel = kernel;
}
public ISomeRepository SomeRepository()
{
return _kernel.Get<ISomeRepository>();
}
public IRepository<SomeObjectType> SomeObjectTypeRepository()
{
return _kernel.Get<IRepository<SomeObjectType>>();
}
public IRepository<T> Repository<T>() where T : class
{
return _kernel.Get<IRepository<T>>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment