Syrx.Commanders.Databases 2.4.0

dotnet add package Syrx.Commanders.Databases --version 2.4.0                
NuGet\Install-Package Syrx.Commanders.Databases -Version 2.4.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="Syrx.Commanders.Databases" Version="2.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Syrx.Commanders.Databases --version 2.4.0                
#r "nuget: Syrx.Commanders.Databases, 2.4.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 Syrx.Commanders.Databases as a Cake Addin
#addin nuget:?package=Syrx.Commanders.Databases&version=2.4.0

// Install Syrx.Commanders.Databases as a Cake Tool
#tool nuget:?package=Syrx.Commanders.Databases&version=2.4.0                

Overview

Syrx is intended to be a project that can access multiple different underlying data stores (not only RDBMSs). This repository hosts code that is common to all RDBMS implementations as well as extensions to make configuration easier.

What follows is a brief overview of each of the projects within this repository.

Table of Contents

  1. Syrx.Commanders.Databases
  2. Syrx.Commanders.Databases.Connectors
  3. Syrx.Commander.Databases.Settings
  4. Syrx.Commander.Databases.Settings.Readers

Syrx.Commanders.Databases

This is the implementation of the ICommander and where Syrx uses Dapper extension methods for reading and writing to an RDBMS. There are multiple overloads for both reading (Query) and writing (Execute) from/to the database as well as asynchronous variants for the same.

[CallerMemberName]

Each method accepts an optional string parameter decorated with the CallerMemberNameAttribute. Using this, and the fully qualified type name of the generic type used by the ICommander<> we can interrogate our settings to resolve to a single CommandSetting entry for the method to be executed.

Example

For example, assuming you have a method called RetrieveAll in a repository exposing a Country type in the namespace of MyProject.Repositories.

namespace MyProject.Repositories
{
    public class CountryRepository(ICommander<CountryRepository> commander) 
    {
        public IEnumerable<Country> RetrieveAll() => commander.Query<Country>();    
    }    
}

In this example, we can see:

  • CountryRepository is passed as a generic type to the ICommander<> which is injected into the class.
  • Our RetrieveAll method has no parameters.

When this method executes, the DatabaseCommander will already know that the fully qualified type for the method being executed is MyProject.Repositories.CountryRepository and, using the [CallerMemberName], know that the method being executed is called RetrieveAll. This allows us to map the method ro be executed to a specific SQL query.

Structurally, you could think of it as being part of a hierarchy:

MyProject.Repositories                      // <-- the namespace
    CountryRepository                       // <-- the type
        RetrieveAll                         // <-- the method
            select * from [dbo].[country]   // <-- the SQL
Overloads

We can support overloads of the same method by passing in the method: argument and adding this overload to our configuration.

namespace MyProject.Repositories
{
    public class CountryRepository(ICommander<CountryRepository> commander) 
    {
        public IEnumerable<Country> RetrieveAll() => commander.Query<Country>();

        public IEnumerable<Country> RetrieveAll(string language) => commander.Query<Country>(new { language }, method:"RetrieveAllByLanguage");
    }    
}

Structurally, you could think of it as being part of a hierarchy:

MyProject.Repositories                                                      // <-- the namespace
    CountryRepository                                                       // <-- the type
        RetrieveAll                                                         // <-- the method
            select * from [dbo].[country]                                   // <-- the SQL
        RetrieveAllByLanguage                                               // <-- the overload
            select * from [dbo].[country] where [language] = @language;     // <-- the overload SQL

Syrx.Commanders.Databases.Connectors

Establishes a connection to a database using the IDbConnection construct.

There's only one class in this project - DatabaseConnector. This class inherits from the IDatabaseConnector which itself inherits from the IConnector<> in the Syrx.Connectors project.

Func<DbProviderFactory>

This class accepts an instance of the ICommanderSettings and a Func<DbProvider> delegate. This delegate is responsible for creating the connection. The ICommanderSettings instance is passed in solely to retrieve the connection string from the aliased ConnectionStringSetting.

This class, and specifically this delegate, are the base type for supporting all other RDBMS implementations.

Inheritance
  • DatabaseConnector
    • IDatabaseConnector
      • IConnector<>

Syrx.Commanders.Databases.Connectors.Extensions

The primary purpose of this project is to provide syntactic sugar extension methods. There are extension methods against the SyrxBuilder as well as IServiceCollection.

The UseConnector method can be used to inject any Func<DbProviderFactory> delegate. This is useful is you need to support an RDBMS that isn't already natively supported by Syrx. As long as the RDBMS client library exposes a DbProviderFactory it can be supported by Syrx.


Syrx.Commander.Databases.Settings

This project is one of the main reason Syrx exists - it's the library which separates the SQL from the .NET code. This is achieved with the CommandSetting type. The properties of this type hold all the necessary information executing a SQL command against an RDBMS. It has very similar properties to the CommandDefinition used by Dapper - this is deliberate as Syrx uses Dapper to execute commands against an RDBMS. Syrx is not itself a micro-orm but a wrapper over Dapper.

As mentioned elsewhere, Syrx uses a unqiue configuration in that it mimics the structure of your code. This is achieved by using the following structure:

  • CommanderSettings
    • NamespaceSettings
      • TypeSettings
        • CommandSetting

Syrx.Commander.Databases.Settings.Extensions

Hosts the builders and extension methods for creating and populating settings.

This is currently the preferred method for configuring Syrx.

Syrx.Commander.Databases.Settings.Extensions.Json

Provides support for configuring Syrx via JSON file.

NOTE:

  • In future, the JSON and XML extensions will be folded into the Readers namespace.

Syrx.Commander.Databases.Settings.Extensions.Xml

Provides support for configuring Syrx via XML file.

NOTE:

  • In future, the JSON and XML extensions will be folded into the Readers namespace.

Syrx.Commander.Databases.Settings.Readers

Readers are used to bridge the DatabaseCommander to the CommanderSettings. It's a really simple type that you're unlikely to have to interact with directly.

In future, the JSON and XML extensions will be folded into the Readers namespace.

Syrx.Commander.Databases.Settings.Readers.Extensions

Provides an extension point to add an IDatabaseCommandReader instance to an IServiceCollection


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Syrx.Commanders.Databases:

Package Downloads
Syrx.SqlServer

This package provides Syrx support for SQL Server databases.

Syrx.MySql

This package provides Syrx support for MySQL databases.

Syrx.Npgsql

This package provides Syrx support for PostgreSQL databases.

Syrx.Commanders.Databases.Extensions

This package hosts extension methods to simplify dependency injection using the IServiceCollection.

Syrx.Commanders.Databases.Oracle

This package hosts special handling for Oracle to support multiple result sets.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.4.0 100 1/19/2025
2.3.0 284 11/22/2024
2.2.0 108 11/21/2024
2.1.0 189 11/15/2024
2.0.0 232 7/5/2024
1.4.0 1,264 3/24/2019
1.3.0 7,009 12/2/2017
1.2.0 1,441 10/18/2017
1.1.0 1,596 10/2/2017
1.0.0 1,485 10/2/2017

Last release on .NET8.0 exclusively. Next release will include .NET9.0.