All Projects → besnik → Generic Repository

besnik / Generic Repository

Generic implementation of Repository pattern in C# .NET

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Generic Repository

Sample Dotnet Core Cqrs Api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
Stars: ✭ 1,273 (+1006.96%)
Mutual labels:  entity-framework, design-patterns
Entitas Csharp
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Stars: ✭ 5,393 (+4589.57%)
Mutual labels:  entity-framework, design-patterns
Calcite Components
Web Components for the Calcite Design System. Built with Stencil JS. Currently in Beta!
Stars: ✭ 96 (-16.52%)
Mutual labels:  design-patterns
When Ts
When: recombinant design pattern for state machines based on gene expression with a temporal model
Stars: ✭ 112 (-2.61%)
Mutual labels:  design-patterns
Ios Learning Materials
📚Curated list of articles, web-resources, tutorials and code repositories that may help you dig a little bit deeper into iOS [and Apple Platforms].
Stars: ✭ 1,380 (+1100%)
Mutual labels:  design-patterns
Designpatterns
Project : Design Patterns Examples in C#
Stars: ✭ 1,337 (+1062.61%)
Mutual labels:  design-patterns
Blazorwasmefcoreexample
Example of a Blazor WebAssembly project that uses Entity Framework Core on the server for data access.
Stars: ✭ 105 (-8.7%)
Mutual labels:  entity-framework
Gang Of Four And Solid Principles In Swift
👨‍👩‍👧‍👦 - My personal Repo to learn all 23 Gang of Four patterns and all SOLID Principles using Swift and Playgrounds
Stars: ✭ 95 (-17.39%)
Mutual labels:  design-patterns
Brazilian Portuguese
Brazilian portuguese translation [WIP]
Stars: ✭ 111 (-3.48%)
Mutual labels:  design-patterns
Tachyons Verbose
Functional CSS for humans. Verbose edition.
Stars: ✭ 102 (-11.3%)
Mutual labels:  design-patterns
Audit.net
An extensible framework to audit executing operations in .NET and .NET Core.
Stars: ✭ 1,647 (+1332.17%)
Mutual labels:  entity-framework
Generic Repository Nodejs Typescript Article
Article's examples
Stars: ✭ 100 (-13.04%)
Mutual labels:  design-patterns
Design Systems Repo
A collection of Design System examples, resources, tools, articles and videos.
Stars: ✭ 95 (-17.39%)
Mutual labels:  design-patterns
Design Patterns
php设计模式
Stars: ✭ 107 (-6.96%)
Mutual labels:  design-patterns
Library Management System Java
📚 A sophisticated Library Management System designed in Java while following the concepts of decoupled layers (entities) and minimal code in interface (GUI).
Stars: ✭ 96 (-16.52%)
Mutual labels:  design-patterns
Swift X Design Patterns
✏️ Design patterns implemented in Swift X. `let X = 5.1`
Stars: ✭ 112 (-2.61%)
Mutual labels:  design-patterns
Paper Code
对一些好的技术文章结合自己的实践经验进行翻译、举例说明等或自己的经验分享。主要包括架构设计、模式设计、模型设计、重构等。
Stars: ✭ 94 (-18.26%)
Mutual labels:  design-patterns
Python Ddd
Python DDD example
Stars: ✭ 100 (-13.04%)
Mutual labels:  design-patterns
Level13
Incremental browser text adventure
Stars: ✭ 103 (-10.43%)
Mutual labels:  entity-framework
Programming Principles
Categorized overview of programming principles & design patterns
Stars: ✭ 1,735 (+1408.7%)
Mutual labels:  design-patterns

Generic Repository

GenericRepository project is generic implementation of Repository pattern in .NET. For detailed discussion please see project's wiki pages and especially Introduction.

Lightweight

It is lightweight thin layer between domain model and data mappers (e.g. ORMs like NHibernate, Linq2Sql or Entity Framework). The goal is to avoid recreating same repositories over and over again in all projects where repository pattern is used. Designed with respect to DDD (domain driven design). Implements Filter pattern and best used with factory and/or Service locator patter (DI/IoC). I used the name specification, but it turned out to be confusing of other design pattern, so from now on I call it filters.

Example of usage:

var customer = new Customer { Name = "Peter Bondra", Age = 37 };
var specificationLocator = this.IoC.Resolve<ISpecificationLocator>();

using ( var unitOfWork = this.IoC.Resolve<IUnitOfWorkFactory>().BeginUnitOfWork() )
{
  ICustomerRepository cr = this.IoC.Resolve<ICustomerRepository>(unitOfWork, specificationLocator);
  
  using ( var transaction = unitOfWork.BeginTransaction() )
  {
	cr.Insert(customer);
	transaction.Commit();
  }
}

Fluent filter pattern

The generic repository natively supports filter pattern that decouples the filter logic (queries) from the repository. It contains extension point for your custom filters and the filter interface (called specification) shall be implemented using fluent interface pattern.

Example of fluent filter pattern usage (I call it specification in the code):

ICustomerRepository customerRepository = 
  this.IoC.Resolve<ICustomerRepository>(unitOfWork, specificationLocator);

IList<Customer> = customerRepository.Specify<ICustomerSpecification>()
  .NameStartsWith("Peter")
  .OlderThan(18)
  .ToResult()
  .Take(3)
  .ToList();

CRUD and DRY

Don't repeat yourself. GenericRepository provides implementation of repository patter, so you can focus on your domain model and business rules, instead of fighting with specific data mapper technology (some knowledge is still required for doing mapping configuration). You can start loading and saving data to the data storage extremly fast. If the Generic repository does not support requested functionalit natively, you can still very easily use underlying data mapper.

Abstraction of data mappers

Nice sideeffect is that it is very easy to switch between several data mappers, for example from Entity Framework to NHibernate and so on.

Learning resource

Last but not least: great learning resource. By implementing generic repository with various data mappers, it is very easy to see the design and architecture differences between the libraries. For example, GetById method differs in LinqToSql and NHibernate, because NHibernate accepts type Object as ID, in comparing to LinqToSql that is strongly typed. This small difference makes it more complex to implement base class for LinqToSql repositories as you can see in the sources. Note that IGenericRepository and it's methods are all strongly typed, the difference is just under the hood. So that was one example. Other can be found in the source codes.

Unit tested

Ships with unit tests. Note: when running tests, make sure to adapt connection strings in config directory (or data mapper configuration). There is a plan to make default data provider some file based database like sql ce, so the unit tests would work on of the box.

Well documented

Source codes fully documented. External documentation and pattern explanation can be found at my blog.

Feedback

I would really like to get feedback what features are missing for your project. The layer is very thin and it is easy to extend and add new features. Contributors are welcome.

Dependencies

The solution file is for Visual Studio 2010 and projects are targeting CLR 4.0 (.NET 4.0); If there is a need for older version of CLR, it is no problem to build it for CLR 2.0 (.NET 2.0, 3.0, 3.5). Some of the linked libraries may still be compiled for CLR 2.0, the plan is to migrate everything to CLR 4.0. Unit tests are using NUnit and Mock frameworks.

Licence

Open to use in commerce and non-commerce projects.

Supported data mappers

  • NHibernate
  • Linq2Sql
  • Entity Framework

Plan is to implement suppport for

  • NoSql data mappers like Mongo, RavenDb, CouchDB, etc.
  • Anything the community requests

You can always implement IGenericRepository interface for your favourite data mapper and push the implementation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].