An example of Generic Entity Framework 6 Code First Repository, utilizing of the repo in a services/business logic class and testing framework examples using BDD style tests. The repoistory supports sync and async calls. One test mocking the repo and another utilizing SqlServerCe for integration testing. This solution example is also utilizing Ninject for DI, NUnit for testing, Moq for mocking.
This is a fully functional generic entity framework repository used by Resgrid (http://resgrid.com) running on Microsoft's Azure utilizing a SQL Azure backend, 2 load balanced web servers, 2 load balanced API servers and 2 workers.
Resgrid is a software as a service (SaaS) logistics, management and communications platform for first responders, volunteer fire departments, career fire, EMS, public safety, HAZMAT, CERT, disaster response, etc.
- Resgrid.Model
- Contains Model/POCO Objects
- Interfaces for Service Layer & Repo
- Resgrid.Repository
- EF Code Configurations
- 1 for Standard Operation
- 1 for Testing (Utilizing auto-create db)
- Context
- Migrations
- RepositoryBase (where all the magic happens)
- GenericRepository Injectable implementation of RepositoryBase
- EF Code Configurations
- Resgrid.Services
- Example Utilization of the generic repo
- Resgrid.Tests
- Example of how a generic repo can be mocked
- Example of how EF can be used to create data intergration tests
When we were looking around for some good example of wrapping Entity Framework inside a repository pattern there were tons of one off examples or examples buried in extremely large projects. Our goal here to show a clean and simple of a generic entity framework repository. Inside the Resgrid.Repository project you can open up the RepositoryBase file to see the meat and potatoes of the generic repo.
Shawn Jackson (@DesignLimbo\designlimbo.com) Jason Jarrett (@staxmanade\staxmanade.com)
Apache 2.0