Bartdebever.Patterns
1.0.1
dotnet add package Bartdebever.Patterns --version 1.0.1
NuGet\Install-Package Bartdebever.Patterns -Version 1.0.1
<PackageReference Include="Bartdebever.Patterns" Version="1.0.1" />
paket add Bartdebever.Patterns --version 1.0.1
#r "nuget: Bartdebever.Patterns, 1.0.1"
// Install Bartdebever.Patterns as a Cake Addin #addin nuget:?package=Bartdebever.Patterns&version=1.0.1 // Install Bartdebever.Patterns as a Cake Tool #tool nuget:?package=Bartdebever.Patterns&version=1.0.1
Bartdebever.Patterns
The popular Repository and Service pattern written for Entity Framework 6 and Core.
Getting Started
There are 3 main classes (with interfaces) to use
IEntity and BaseEntity
These are the main classes to use when defining entities.
This will make sure that the Id
property is defined and set as the key.
When using the BaseEntity
class, the Id
property will be a long
.
The IEntity
interfaces allows the developer to define the type that the Id
property should have.
IRepository, BaseRepository and EntityRepository
The IRepository
defines the methods available to be used in the service
.
These methods are the basic CRUD (Create, read, update and delete) actions.
Note that if you are using Entity Framework 6, there is no update method available. Tracked entities should be gathered from the database and stay tracked when updated.
The BaseRepository
provides a base implementation for these methods using the
DbSet<>
class.
This DbSet<>
is not available in the repository itself, there is the Queryable
property. This IQueryable
should be used for querying the database.
This is done cause I generally believe using DbSet<>
goes hand in hand with writing
hacky, unmaintainable code.
The EntityRepository
is written so that it works off the BaseEntity
class.
This means the developer does not need to specify the TKey
being used.
IService, BaseService and EntityService
The same principles as for the Repository
side of things is still at play here.
The IService
defines the methods to be used for CRUD actions. The BaseService
provides an implementation for these methods using IEntity
.
EntityService
wraps these methods using BaseEntity
.
Dependency injection
Both BaseRepository
and BaseService
make use of constructor based dependency injection.
The repository relies on a DbContext
being inserted into its constructor.
The service relies on a IRepository
being inserted into its constructor.
It is highly encouraged to use the dependency injection pattern when using this package.
Contributing
This package was mostly made for personal use but I do accept contributions. Feel free to send in a pull request or issue.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- EntityFramework (>= 6.2.0)
-
.NETStandard 2.0
- Microsoft.EntityFrameworkCore (>= 2.2.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.