工作單元和儲存庫框架|官方URF、可追蹤實體和設計工廠團隊
URF.Core 功能完整,現在與 URF.NET(舊版 .NET)完全同等。 URF.Core 已經進行了完全重寫,重點關注架構、設計和實現以及實現 vNext 的最高請求,您可以查看我們的 URF.Core.Sample w/ ASP.NET Core Web API、OData、帶有Angular 和Kendo UI 的完整CRUD 範例。
從版本 3.1.1 開始,新增了對 NoSQL 文件資料庫的支援以及 MongoDb 的實作。
已為 EF Core 3.x 和 MongoDb 提供範例。
忠於(傳統)URF.NET 的足跡。 URF.Core URF.Core(總共 7 個類別)與 URF.NET(總共 12 個類別)。
我們已經使每個實作都是虛擬的,因此對於任何團隊/專案/開發人員用例以及邊緣情況都可以覆蓋。
一如既往,這是團隊和社區內部之間的宗教辯論。與(傳統)URF.NET 一樣,我們為團隊提供了選擇 IQueryable 或 IEnumerable 的選項,甚至可以同時選擇兩者,具體取決於您團隊的架構、設計和實現以及風格。作為 URF.NET 以及認為儲存庫模式將IQueryable
公開為洩漏抽象的團隊,只需使用 URF 的IQuery
API,它將為您提供IQueryable 的所有Fluent 功能,但將傳回純實體或IEnumerable 與使用IQueryable 相比,再次是URF .Core 和 URF.NET 都支持,因此團隊可以完全自由地選擇 3 個路徑/選項中的哪一個對其團隊/專案最有意義。
public class ProductsController : ODataController
{
private readonly IProductService _productService ;
private readonly IUnitOfWork _unitOfWork ;
public ProductsController (
IProductService productService ,
IUnitOfWork unitOfWork )
{
_productService = productService ;
_unitOfWork = unitOfWork ;
}
// e.g. GET odata/Products?$skip=2&$top=10
[ EnableQuery ]
public IQueryable < Products > Get ( ) => _productService . Queryable ( ) ;
// e.g. GET odata/Products(37)
public async Task < IActionResult > Get ( [ FromODataUri ] int key )
{
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
var product = await _productService . FindAsync ( key ) ;
if ( product == null )
return NotFound ( ) ;
return Ok ( product ) ;
}
// e.g. PUT odata/Products(37)
public async Task < IActionResult > Put ( [ FromODataUri ] int key , [ FromBody ] Products products )
{
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
if ( key != products . ProductId )
return BadRequest ( ) ;
_productService . Update ( products ) ;
try
{
await _unitOfWork . SaveChangesAsync ( ) ;
}
catch ( DbUpdateConcurrencyException )
{
if ( ! await _productService . ExistsAsync ( key ) )
return NotFound ( ) ;
throw ;
}
return NoContent ( ) ;
}
// e.g. PUT odata/Products
public async Task < IActionResult > Post ( [ FromBody ] Products products )
{
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
_productService . Insert ( products ) ;
await _unitOfWork . SaveChangesAsync ( ) ;
return Created ( products ) ;
}
// e.g. PATCH, MERGE odata/Products(37)
[ AcceptVerbs ( " PATCH " , " MERGE " ) ]
public async Task < IActionResult > Patch ( [ FromODataUri ] int key , [ FromBody ] Delta < Products > product )
{
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
var entity = await _productService . FindAsync ( key ) ;
if ( entity == null )
return NotFound ( ) ;
product . Patch ( entity ) ;
_productService . Update ( entity ) ;
try
{
await _unitOfWork . SaveChangesAsync ( ) ;
}
catch ( DbUpdateConcurrencyException )
{
if ( ! await _productService . ExistsAsync ( key ) )
return NotFound ( ) ;
throw ;
}
return Updated ( entity ) ;
}
// e.g. DELETE odata/Products(37)
public async Task < IActionResult > Delete ( [ FromODataUri ] int key )
{
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
var result = await _productService . DeleteAsync ( key ) ;
if ( ! result )
return NotFound ( ) ;
await _unitOfWork . SaveChangesAsync ( ) ;
return StatusCode ( ( int ) HttpStatusCode . NoContent ) ;
}
}
URF.Core 已完全重寫,現在所有內容都完全是開箱即用的task
、 async
、 await
。這樣,團隊將自動獲得非同步效能改進的最佳執行緒管理。
© 2017 URF.NET 版權所有。