TheStandardBox.Data 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TheStandardBox.Data --version 1.0.2                
NuGet\Install-Package TheStandardBox.Data -Version 1.0.2                
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="TheStandardBox.Data" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TheStandardBox.Data --version 1.0.2                
#r "nuget: TheStandardBox.Data, 1.0.2"                
#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 TheStandardBox.Data as a Cake Addin
#addin nuget:?package=TheStandardBox.Data&version=1.0.2

// Install TheStandardBox.Data as a Cake Tool
#tool nuget:?package=TheStandardBox.Data&version=1.0.2                

TheStandardBox

A .NET Library for essential code according to The Standard

  • TheStandardBox.Core : Nuget
  • TheStandardBox.Data : Nuget
  • TheStandardBox.Data.Tests.Unit : Nuget

Installation

Install the nuget package in your API project:

NuGet\Install-Package TheStandardBox.Data -Version 1.0.0

How to use?

This library will allow to you to use easly a sort of standard Storage Broker, Foundation Servicer and Controller:

Add your models

Your models, that represents your database entities, should implement the interface IStandardEntity of the library:

    public interface IStandardEntity
    {
        Guid Id { get; set; }

        DateTimeOffset CreatedDate { get; set; }

        DateTimeOffset UpdatedDate { get; set; }
    }

For example an entity WeatherForecast looks like:

    public class WeatherForecast : IStandardEntity
    {
        public Guid Id { get; set; }

        public DateTime Date { get; set; }

        public int TemperatureC { get; set; }

        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

        public string Summary { get; set; }

        public DateTimeOffset CreatedDate { get; set; }

        public DateTimeOffset UpdatedDate { get; set; }
    }

Standard Storage Broker

In order to define your DbSets ou need to create a new storage broker that inhirates from StandardStorageBroker:

    public class StorageBroker : StandardStorageBroker
    {
        public StorageBroker(IConfiguration configuration)
            : base(configuration)
        { }

        public DbSet<WeatherForecast> WeatherForecasts { get; set; } 
    }
Connection String

By default TheStandardBox reads the connection string from your configuration by the name DefaultConnection. You can define the name of your connection string:

    public class StorageBroker : StandardStorageBroker
    {
        public StorageBroker(IConfiguration configuration)
            : base(configuration)
        { }

        protected override string DefaultConnectionName => "NEW_CONNECTION_STRING_NAME";

        public DbSet<WeatherForecast> WeatherForecasts { get; set; } 
    }
Uses NoTracking Behavior

To use the NoTracking behavior or not, override the property UsesNoTrackingBehavior (By default true):

    protected override bool UsesNoTrackingBehavior => false;

Add TheStandard Box

Add the library as following in the Program.cs file of your API project:

    builder.Services.AddTheStandardBoxData<StorageBroker>();

Migrations

Dont forget to add a migration by running > Add-Migration [MIGRATION_NAME].

Foundation Service

For each entity add a standard foundation service as following:

     builder.Services.AddStandardFoundationService<WeatherForecast>();

Unit testing ?

It is very important to unit test your services, using TheStandardBox this is now very easy. You need only to create your test class as following:

    public class WeatherServiceTests : StandardServiceTests<WeatherForecast>
    { }

Support

For any question or infromation: contact@mahdhi.com

Product Compatible and additional computed target framework versions.
.NET 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. 
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 TheStandardBox.Data:

Package Downloads
TheStandardBox.Data.Tests.Unit

A .NET Library for essential unit testing code according to The Standard

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 276 3/7/2023
1.0.3 368 11/11/2022
1.0.2 355 11/11/2022
1.0.1 529 11/7/2022
1.0.0 436 11/4/2022