工作单元和存储库框架|官方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 功能,但是将返回纯 Entity 或 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 版权所有。