TheStandardBox.Core
1.0.4
dotnet add package TheStandardBox.Core --version 1.0.4
NuGet\Install-Package TheStandardBox.Core -Version 1.0.4
<PackageReference Include="TheStandardBox.Core" Version="1.0.4" />
paket add TheStandardBox.Core --version 1.0.4
#r "nuget: TheStandardBox.Core, 1.0.4"
// Install TheStandardBox.Core as a Cake Addin #addin nuget:?package=TheStandardBox.Core&version=1.0.4 // Install TheStandardBox.Core as a Cake Tool #tool nuget:?package=TheStandardBox.Core&version=1.0.4
TheStandardBox
A .NET Library for essential code according to The Standard
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 | 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
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.Logging (>= 6.0.0)
- Xeption (>= 2.5.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TheStandardBox.Core:
Package | Downloads |
---|---|
TheStandardBox.Data
A .NET Library for essential code according to The Standard |
GitHub repositories
This package is not used by any popular GitHub repositories.