Hydrogen.Repo.Abstractions 1.5.0

dotnet add package Hydrogen.Repo.Abstractions --version 1.5.0                
NuGet\Install-Package Hydrogen.Repo.Abstractions -Version 1.5.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hydrogen.Repo.Abstractions" Version="1.5.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Hydrogen.Repo.Abstractions --version 1.5.0                
#r "nuget: Hydrogen.Repo.Abstractions, 1.5.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Hydrogen.Repo.Abstractions as a Cake Addin
#addin nuget:?package=Hydrogen.Repo.Abstractions&version=1.5.0

// Install Hydrogen.Repo.Abstractions as a Cake Tool
#tool nuget:?package=Hydrogen.Repo.Abstractions&version=1.5.0                

Hydrogen Repo

This package uses SqlKata as query builder, if you have doubts check its documentation.

Installation

dotnet add package Hydrogen.Repo
dotnet add package Hydrogen.Repo.Abstractions

Settings

var connectionBuilder = new NpgsqlConnectionStringBuilder()
{
    Host = "localhost",
    Port = 5432,
    Username = "postgres",
    Password = "1234567890",
    Database = "master"
};
        
var npgsqlConnection = new NpgsqlConnection(connectionBuilder.ConnectionString);

collection.AddScoped(_ => new HydrogenContext(connection, DbConnectionType.Npgsql));
collection.AddScoped<IHydrogenUnitOfWork, HydrogenUnitOfWork>(); // Only if you need transactions

Repositories

Create a model

The model interface, implements the Id field and a dynamic type.

public class User : IHydrogenModel<Guid>
{
      [AutoGenerateGuid]
      public Guid Id {  get; set; }
      public Guid RoleId { get; set; }
      public string Name { get; set; }
      public string LastName { get; set; }
      public string? Email { get; set; }
      public string? PhoneNumber { get; set; }
      public string Password { get; set; }
}

Create repository

The repository already implements several basic functions.

public interface IUserRepository : IHydrogenRepository<User, Guid>
{
    // Add your functions
}

The abstract class implements the functions of the base interface.

public class UserRepository : HydrogenRepository<User, Guid>, IUserRepository
{
    public UserRepository(HydrogenContext hydrogenContext) : base(hydrogenContext, "Users" //<- Table name)
    {
    }
}

Add to the service collection

var connectionBuilder = new NpgsqlConnectionStringBuilder()
{
    Host = "localhost",
    Port = 5432,
    Username = "postgres",
    Password = "1234567890",
    Database = "master"
};
        
var npgsqlConnection = new NpgsqlConnection(connectionBuilder.ConnectionString);

collection.AddScoped(_ => new HydrogenContext(connection, DbConnectionType.Npgsql));
collection.AddScoped<IHydrogenUnitOfWork, HydrogenUnitOfWork>();
collection.AddScoped<IUserRepository, UserRepository>();

Use in a service

private readonly IUserRepository _userRepository;

public OptionService(IUserRepository userRepository)
{
    _userRepository = userRepository;
}

public async Task<IEnumerable<UserDto>> GetAllAsync(CancellationToken ct)
{
    return _userRepository.GetAsync<UserDto>(ct);
}

Available functions

  • Any
  • Count
  • Insert
  • Bulk insert
  • Update
  • Delete
  • Get
  • Pagination
  • First
  • First or default
Product 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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Hydrogen.Repo.Abstractions:

Package Downloads
Hydrogen.Repo

A repository with basic functions

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 156 9/16/2024