All Projects → TBertuzzi → RepositoryHelpers

TBertuzzi / RepositoryHelpers

Licence: other
📦 Extensions for HttpClient and Custom Repository based on dapper

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to RepositoryHelpers

Korio
Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3
Stars: ✭ 282 (+1181.82%)
Mutual labels:  asynchronous, httpclient
Request.swift
A tiny HTTP client written in swift. URLSession alternative
Stars: ✭ 14 (-36.36%)
Mutual labels:  asynchronous, httpclient
Aspnetcore Practice
ASP.NET Core 專案練習集合,ASP.NET Core Practice Projects
Stars: ✭ 80 (+263.64%)
Mutual labels:  httpclient, dapper
Sttp
The Scala HTTP client you always wanted!
Stars: ✭ 1,078 (+4800%)
Mutual labels:  asynchronous, httpclient
APICorePayLots
Web API designed in Asp.NET Core 3.1, using Dapper and Entity Framework Core, Repository Pattern, Identity
Stars: ✭ 13 (-40.91%)
Mutual labels:  identity, dapper
AppListManager
📱 AppListManager (Android Library) makes managing application and activity lists easy.
Stars: ✭ 59 (+168.18%)
Mutual labels:  asynchronous, asynctask
Transmittable Thread Local
📌 TransmittableThreadLocal (TTL), the missing Java™ std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
Stars: ✭ 4,678 (+21163.64%)
Mutual labels:  asynchronous, dapper
Identity.dapper
Identity package that uses Dapper instead EntityFramework for use with .NET Core
Stars: ✭ 234 (+963.64%)
Mutual labels:  identity, dapper
esa-httpclient
An asynchronous event-driven HTTP client based on netty.
Stars: ✭ 82 (+272.73%)
Mutual labels:  asynchronous, httpclient
aioudp
Asyncio UDP server
Stars: ✭ 21 (-4.55%)
Mutual labels:  asynchronous, asynctask
dapper-repositories
CRUD for Dapper
Stars: ✭ 523 (+2277.27%)
Mutual labels:  dapper, dapper-extensions
ring-channel
Bounded MPMC channel abstraction on top of a ring buffer
Stars: ✭ 24 (+9.09%)
Mutual labels:  asynchronous
react-redux-aspnet-core-webapi
No description or website provided.
Stars: ✭ 34 (+54.55%)
Mutual labels:  dapper
aspnet-mvc5-starter-template
Asp.Net MVC 5 Starter Kit is a S.O.L.I.D, clean and globalized template with all the necessary boilerplate, ready to go.
Stars: ✭ 39 (+77.27%)
Mutual labels:  dapper
yona
Yona is a modern take on a dynamic general-purpose programming language with advanced functional programming, minimalistic ML-like syntax, strict evaluation, for GraalVM polyglot virtual machine (VM).
Stars: ✭ 113 (+413.64%)
Mutual labels:  asynchronous
crawler
A simple and flexible web crawler framework for java.
Stars: ✭ 20 (-9.09%)
Mutual labels:  httpclient
glosarium
Glosarium adalah suatu daftar alfabetis istilah dalam suatu ranah pengetahuan tertentu yang dilengkapi dengan definisi untuk istilah-istilah tersebut.
Stars: ✭ 12 (-45.45%)
Mutual labels:  dictionary
cyberdic
An auxiliary spellcheck dictionary that corresponds with the Bishop Fox Cybersecurity Style Guide
Stars: ✭ 63 (+186.36%)
Mutual labels:  dictionary
mtxclient
Client API library for Matrix, built on top of Boost.Asio
Stars: ✭ 21 (-4.55%)
Mutual labels:  httpclient
RestSharpFramework
Framework for testing RESTful Services with RestSharp and C# HTTP Client
Stars: ✭ 18 (-18.18%)
Mutual labels:  httpclient

RepositoryHelpers

Extensions for HttpClient and Custom Repository based on dapper

This is the component, works on .NET Core and.NET Framework

Info

Code Quality Build Nuget Contributors
Codacy Badge Publish package on NuGet NuGet GitHub contributors

Build History

Build history

Platform Support

RepositoryHelpers is a .NET Standard 2.0 library.

Database/Dapper Extensions

Use the connection class to define the type of database and connection string

 var connection = new Connection()
 {
     Database = RepositoryHelpers.Utils.DataBaseType.SqlServer, //RepositoryHelpers.Utils.DataBaseType.Oracle
     ConnectionString = "Your string"
 };

Create a CustomRepository of the type of object you want to return

  var Repository = new CustomRepository<User>(conecction);

Mapping with Attributes:

[DapperIgnore] // Property will be ignored in select, insert and update
public string InternalControl { get; set; }
[PrimaryKey] // Primary key
public int MyCustomId { get; set; }
[PrimaryKey]
[Identity] //Indicates that the primary key has some identity, sequence or auto increment
public int MyBdIdIndentity { get; set; }

//You can optionally map the name of the Database table that refers to the entity
[Table("Product")] 
public class Products
{
    public int Id { get; set; }
}

Mapping with FluentMapper:

Install and use the Dapper.FluentMap.Dommel package to map your entities by creating the specific classes inherited from DommelEntityMap:

public class ProductMap : DommelEntityMap<Product>
{
    public ProductMap()
    {
        Map(p => p.Id).IsKey().IsIdentity();
        Map(p => p.Category).Ignore();
    }
}

You can define the name of the table that will be mapped

public class ProductMap : DommelEntityMap<Product>
{
    public ProductMap()
    {
        ToTable("Product");
        Map(p => p.Id).IsKey().IsIdentity();
        Map(p => p.Category).Ignore();
    }
}

After that, you must configure Dapper.FluentMap.Dommel in RepositoryHelpers:

Mapper.Initialize(c =>
{
    c.AddMap(new ProductMap());
});

Get Data:

To get results just use the Get method. can be syncronous or asynchronous

//Get All Users
var usersAsync = await Repository.GetAsync();
var users = Repository.Get();

//Get User by Id
var userAsync = await Repository.GetByIdAsync(1);
var user = Repository.GetById(1);

//Get by CustomQuery with parameters
var customQuery = "Select name from user where login = @userLogin";
var parameters = new Dictionary<string, object> { { "userLogin", "bertuzzi" } };
var resultASync = await Repository.GetAsync(customQuery, parameters);
var result = Repository.Get(customQuery, parameters);

//Get by CustomQuery without parameters
var customQuery = "Select * from user";
var resultASync = await Repository.GetAsync(customQuery);
var result = Repository.Get(customQuery);

//Get by multi-mapping custom query with 2 input types
var customQuery = "Select * from user inner join category on user.categoryId = category.Id where login = @userLogin";
var user = Repository.Get<User, Category, User>(
    customQuery,
    map: (user, category) => 
    {
        user.Category = category;
        return user;
    });

//Get by multi-mapping custom query with 2 input types (When the field that we should split and read the second object is different from "Id")
var customQuery = "Select * from user inner join state on user.stateCode = state.Code where login = @userLogin";
var user = Repository.Get<User, State, User>(
    customQuery,
    map: (user, state) => 
    {
        user.State = state;
        return user;
    },
    parameters,
    splitOn: "Code"
);

//Get by multi-mapping custom query with an arbitrary number of input types
var customQuery = "Select * from user inner join category on user.categoryId = category.Id where login = @userLogin";
var user = Repository.Get(
    customQuery,
    new[] { typeof(User), typeof(Category) },
    map: (types) => 
    {
        var user = (types[0] as User);
        user.Category = (types[1] as Category);
        return user;
    });

Insert Data :

user identity parameter to return the id if your insert needs

Repository.Insert(NewUser, true);

Update data

Repository.Update(updateUser);
Repository.UpdateAsync(updateUser);

Delete data

Repository.Delete(1);
Repository.DeleteAsync(1);

You can use ADO if you need

//Return DataSet
var customQuery = "Select name from user where login = @userLogin";
var parameters = new Dictionary<string, object> { { "userLogin", "bertuzzi" } };
Repository.GetDataSet(customQuery, parameters);

//ExecuteQuery
Repository.ExecuteQueryAsync();
Repository.ExecuteQuery();

//ExecuteScalar
Repository.ExecuteScalarAsync();
Repository.ExecuteScalar();

//ExecuteProcedure
Repository.ExecuteProcedureAsync();
Repository.ExecuteProcedure();

CustomTransaction is possible to use transaction

CustomTransaction customTransaction = new CustomTransaction(YourConnection);

customTransaction.BeginTransaction();
customTransaction.CommitTransaction();
customTransaction.RollbackTransaction();

//Sample
Repository.ExecuteQuery("yourquery", parameters, customTransaction);

DapperIgnore : if you want some property of your object to be ignored by Dapper, when inserting or updating, just use the attribute. PrimaryKey : Define your primary key. It is used for queries, updates, and deletes. IdentityIgnore: Determines that the field has identity, autoincrement ... Warns the repository to ignore it that the database will manage the field

*TIP Create a ConnectionHelper for BaseRepository and BaseTransaction to declare the connection only once :

 public sealed class ConnectionHelper
    {
        static ConnectionHelper _instance;
        public static ConnectionHelper Instance
        {
            get { return _instance ?? (_instance = new ConnectionHelper()); }
        }
        private ConnectionHelper() 
        {
            Connection = new Connection()
            {
                Database = RepositoryHelpers.Utils.DataBaseType.SqlServer,
                ConnectionString = "YourString"
            };
        }
        public Connection Connection { get; }
    }
    
 public class BaseRepository<T>
    {
        protected readonly CustomRepository<T> Repository;

        protected BaseRepository()
        {
            Repository = new CustomRepository<T>(ConnectionHelper.Instance.Connection);
        }
    }
    
     public class BaseTransaction : CustomTransaction
    {
        public BaseTransaction() :
             base(ConnectionHelper.Instance.Connection)
        {
           
        }
    }
    

LiteDB Extensions

coming soon ..

HttpClient Extensions

Extensions to make using HttpClient easy.

To enable and use Follow the doc : https://github.com/TBertuzzi/HttpExtension

Samples coming soon ..

Special Thanks to project contributors

Special Thanks users who reported bugs and helped improve the package :

  • Thiago Vieira
  • Luis Paulo Souza
  • Alexandre Harich

The RepositoryHelpers was developed by Thiago Bertuzzi under the MIT license.

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].