ProphetsWay.BaseDataAccess
2.1.5-429.Beta
Prefix Reserved
See the version list below for details.
dotnet add package ProphetsWay.BaseDataAccess --version 2.1.5-429.Beta
NuGet\Install-Package ProphetsWay.BaseDataAccess -Version 2.1.5-429.Beta
<PackageReference Include="ProphetsWay.BaseDataAccess" Version="2.1.5-429.Beta" />
paket add ProphetsWay.BaseDataAccess --version 2.1.5-429.Beta
#r "nuget: ProphetsWay.BaseDataAccess, 2.1.5-429.Beta"
// Install ProphetsWay.BaseDataAccess as a Cake Addin #addin nuget:?package=ProphetsWay.BaseDataAccess&version=2.1.5-429.Beta&prerelease // Install ProphetsWay.BaseDataAccess as a Cake Tool #tool nuget:?package=ProphetsWay.BaseDataAccess&version=2.1.5-429.Beta&prerelease
ProphetsWay.BaseDataAccess
BaseDataAccess is a light library that is meant to help decouple your software's business logic projects from your Data Access Layer (DAL) implementation. With some new technologies, it is easy to allow yourself to create entity/models in your DAL and use them directly in your business layers, however this makes it difficult to replace your DAL implementation if you decide to change how/what is hosting your data. By adhering to a specific project dedicated to the models and interfaces required for your solution, you aren't restricted to the models that are created for you by your data layer implementation.
Getting Started
BaseDataAccess is a lightweight project that consists of mostly just interfaces, but it also has a base abstract class you can utilize for convenience within your project. This base class does use Reflection to work some magic, and if you're concerned about speed, you can override those virtual methods and manually evaluate them (or not use the base abstract class and just implement the interface on your own).
Prerequisites
You can pull a copy of the source code from GitHub, or you can reference the library from NuGet.org from within Visual Studio.
Install-Package ProphetsWay.BaseDataAccess
dotnet add package ProphetsWay.BaseDataAccess
Referencing and Using
The approach to use this project is that you want to create a new project in your solution to specify the data access requirements. Generally my naming convention is "[ProjectName].DataAccess" and then the project that implements the actual data access layer is "[ProjectName].DataAccess.[ImplementationName]". For "ImplementationName" I generally use a shortcut name to identify what the implementation is working with (ex: MSSQL, MySQL, Oracle, SQLite).
[ProjectName].DataAccess
In this project, I recommend the folder layout as follows: root
- Entities / Models Folder
- IDaos Folder
- I[ProjectName]DataAccess Class
Entities/Models
The Entities / Models folder name is really a personal preference on the naming convention. The point is that you define the entities that you will be using in your solution here. Defining them outside of the DAL implementation allows you to use them however you see fit within your application. Any new DAL implementation will have to interact with the models defined here-in. All of your entities must inherit the interface IBaseEntity. This is to flag the entities as compatible with the other interfaces.
IDaos
The IDaos folder is meant to specify what actions you want for each specific entity in your Entities folder. Generally you should name your interfaces
I[EntityName]Dao so that it's quick and easy to identify which files reference which entities. Your interface should inherit from one of the base DAO interfaces.
Using one of the base interfaces will automatically include specific methods, however this DAO is where you will also specify any additional functionality
that you need this entity to have. (ex: IList<Customer> GetCustomersByCompanyId(int companyId);
to be specified on the ICustomerDao
)
All of the base interfaces are generic and require a type T to be specified, here you will specify the type of the entity this DAO is for.
public interface ICustomerDao : IBaseDao<Customer>
IBaseDao
IBaseDao specifies your basic CRUD calls: Get, Insert, Update, and Delete. Each call does require a parameter of the type of entity to be passed
to it, even for Get and Delete where you might normally just need the "Id" of the record. This is done on purpose so that all interfaces for all entities have
unique method signatures for use in the master interface (discussed in the next section). If you do not like/want this style of functionality, you can skip
all three of these BaseDao interfaces completely and manually create all the CRUD calls in each entity IDao (as well as whatever other functionality you need).
The only thing to remember is that you must make each method signature unique
(so instead of just T Get(T item);
you have Customer GetCustomer(int customerId);
))
T Get(T item);
void Insert(T item);
int Update(T item);
int Delete(T item);
IBaseGetAllDao
IBaseGetAllDao inherits from IBaseDao, but additionally specifies a GetAll call. This call also requires the parameter similar to the above mentioned situation.
IList<T> GetAll(T item);
IBasePagedDao
IBasePagedDao also inherits from IBaseDao, and additionally specifies a GetCount and GetPaged calls. More of the same with the required parameters, however these functions are used to get the upper boundary of how many of an entity you have, and then getting a particular subset of them; useful for user interface based queries when trying to optimize data being queried and sent to your front end.
IList<T> GetPaged(T item, int skip, int take);
int GetCount(T item);
I[ProjectName]DataAccess
This is the master interface for your DAL implementation. This shouldn't have any methods manually specified in it, this should be an interface of interfaces. In here you'll inherit all the IDao's you created for each of your entities before. In some cases you might have some functionality that doesn't persist to a particular entity and don't feel like it fits in an any entity's DAO, in those cases you would put the method signature here.
[ProjectName].DataAccess.[ImplementationName]
So technically, you can implement your DAL however you want to, so long as your main point of instantiation inherits/implements the IDataAccess interface defined above.
Currently my approach has been to create a DAO for each IDao specified, that way it's easier to find things in your source code.
internal class CustomerDao : ICustomerDao
will set you up so that all the required CRUD calls and other methods you specified will be added and typed to
the correct entity type. I recommend using internal on the specific DAO's as these are separate for the convenience of the developer and separation of logic, but
shouldn't be accessible outside of the project, only the class implementing IDataAccess should be created and accessible outside of this project.
Depending on your actual implementation, you might have a bunch of other stuff in this project to support how the DAOs actually interact with the data storage you're using. However the final piece to mention here is the main IDataAccess implementation. Generally I name this class [ProjectName]DataAccess, but it doesn't matter. If you created the separate DAOs for each entity, then in here you will have to instantiate each of those DAOs and just pass thru each method signature/call into each specific DAO.
public class ExampleDataAccess : BaseDataAccessInt, IExampleDataAccess
{
private readonly ICustomerDao _customerDao = new CustomerDao();
public Customer Get(Customer item){
return _customerDao.Get(item);
}
}
Running the tests
The library has 21 unit tests currently. I tried to cover everything possible. They are created with an XUnit test project, as well as an Example project.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- G. Gordon Nasseri - Initial work - ProphetManX
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for details
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 is compatible. net452 is compatible. net46 is compatible. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 is compatible. net472 was computed. net48 is compatible. 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. |
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.5.1
- No dependencies.
-
.NETFramework 4.5.2
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.6.1
- No dependencies.
-
.NETFramework 4.7.1
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ProphetsWay.BaseDataAccess:
Package | Downloads |
---|---|
ProphetsWay.EFTools
A small library that is useful when utilizing EntityFramework for a Data Access Layer (DAL) while adhering to Business Layer to DAL decoupling. This uses the paradigm explained in https://github.com/ProphetManX/ProphetsWay.BaseDataAccess. See the README for more information. For more information on this project, please go to https://github.com/ProphetManX/ProphetsWay.EFTools. |
|
ProphetsWay.iBatisTools
A small library that is useful when utilizing iBatisNet for a Data Access Layer (DAL). Go to https://github.com/ProphetManX/ProphetsWay.iBatisTools for more information. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.0 | 616 | 8/16/2022 |
2.2.0-447.Beta | 95 | 8/16/2022 |
2.2.0-447.Alpha | 353 | 8/15/2022 |
2.1.5 | 846 | 8/10/2022 |
2.1.5-431.Beta | 104 | 8/10/2022 |
2.1.5-431.Alpha | 101 | 8/9/2022 |
2.1.5-429.Beta | 95 | 8/9/2022 |
2.1.5-429.Alpha | 99 | 8/9/2022 |
2.1.5-427.Alpha | 103 | 8/9/2022 |
2.1.4 | 462 | 5/11/2022 |
2.1.4-416.Beta | 482 | 5/11/2022 |
2.1.4-416.Alpha | 468 | 5/11/2022 |
2.1.4-412.Alpha | 466 | 5/11/2022 |
2.1.4-410.Alpha | 477 | 5/11/2022 |
2.1.4-409.Alpha | 108 | 5/10/2022 |
2.1.4-393.Beta | 124 | 5/7/2022 |
2.1.4-393.Alpha | 123 | 5/7/2022 |
2.1.4-392.Alpha | 122 | 5/7/2022 |
2.1.3 | 436 | 5/6/2022 |
2.1.3-385.Beta | 114 | 5/6/2022 |
2.1.3-385.Alpha | 120 | 5/6/2022 |
2.1.3-367.Alpha | 118 | 4/28/2022 |
2.1.2 | 458 | 4/28/2022 |
2.1.2-365.Alpha | 117 | 4/28/2022 |
2.1.2-363.Beta | 118 | 4/28/2022 |
2.1.2-363.Alpha | 113 | 4/28/2022 |
2.1.1-349.Alpha | 153 | 8/26/2021 |
2.1.1-343.Alpha | 143 | 8/26/2021 |
2.1.1-293.Alpha | 158 | 8/16/2021 |
2.1.1-292.Alpha | 159 | 8/16/2021 |
2.1.0-315.Alpha | 140 | 8/19/2021 |
2.1.0-307.Alpha | 138 | 8/19/2021 |
2.1.0-287.Beta | 153 | 2/2/2021 |
2.1.0-287.Alpha | 148 | 2/1/2021 |
2.1.0-285.Alpha | 157 | 2/1/2021 |
2.1.0-283.Beta | 159 | 2/1/2021 |
2.1.0-283.Alpha | 156 | 2/1/2021 |
2.1.0-281.Alpha | 170 | 2/1/2021 |
2.0.0 | 406 | 2/1/2021 |
2.0.0-273.Beta | 153 | 2/1/2021 |
2.0.0-273.Alpha | 157 | 2/1/2021 |
2.0.0-267.Beta | 222 | 1/28/2021 |
2.0.0-267.Alpha | 148 | 1/28/2021 |
2.0.0-262.Beta | 158 | 1/28/2021 |
2.0.0-262.Alpha | 153 | 1/28/2021 |
2.0.0-253.Beta | 160 | 1/28/2021 |
2.0.0-253.Alpha | 203 | 1/27/2021 |
1.1.1 | 838 | 6/2/2020 |
1.1.1-171.Beta | 288 | 6/2/2020 |
1.1.1-171.Alpha | 280 | 6/2/2020 |
1.1.0 | 548 | 5/31/2020 |
1.1.0-126.Beta | 312 | 5/19/2020 |
1.1.0-126.Alpha | 279 | 5/19/2020 |
1.0.0 | 569 | 3/24/2019 |
1.0.0-Beta-69 | 420 | 3/24/2019 |
1.0.0-Beta-65 | 410 | 3/23/2019 |
1.0.0-Alpha-83 | 436 | 3/24/2019 |
1.0.0-Alpha-82 | 445 | 3/24/2019 |
1.0.0-Alpha-69 | 420 | 3/24/2019 |
1.0.0-Alpha-68 | 414 | 3/24/2019 |
1.0.0-Alpha-65 | 429 | 3/23/2019 |
1.0.0-Alpha-64 | 424 | 3/23/2019 |
1.0.0-Alpha-61 | 419 | 3/23/2019 |
0.0.0-Alpha-60 | 416 | 3/23/2019 |
# v2.1.5
### Added Generic CRUD Calls
Added the ability to call ```Insert```, ```Update```, and ```Delete``` generically, similar to how ```Get<\T>(int id)``` works already.