TheStandardBox.Data
1.0.0
See the version list below for details.
dotnet add package TheStandardBox.Data --version 1.0.0
NuGet\Install-Package TheStandardBox.Data -Version 1.0.0
<PackageReference Include="TheStandardBox.Data" Version="1.0.0" />
paket add TheStandardBox.Data --version 1.0.0
#r "nuget: TheStandardBox.Data, 1.0.0"
// Install TheStandardBox.Data as a Cake Addin #addin nuget:?package=TheStandardBox.Data&version=1.0.0 // Install TheStandardBox.Data as a Cake Tool #tool nuget:?package=TheStandardBox.Data&version=1.0.0
TheStandardBox
A .NET Library for essential code according to The Standard
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 | Versions 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. |
-
net6.0
- EFxceptions (>= 0.4.5)
- Microsoft.EntityFrameworkCore.SqlServer (>= 6.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- RESTFulSense (>= 2.9.0)
- TheStandardBox.Core (>= 1.0.0)
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.