Skip to content
forked from urfnet/URF.Core

Unit of Work & Repositories Framework - .NET Core, NET Standard, EntityFramework Core. 100% extensible & lightweight. Live demo: https://goo.gl/QpJVgd

License

Notifications You must be signed in to change notification settings

ryletko/URF.Core

Repository files navigation

URF.Core

Unit-of-Work & Repository Framework | Official URF & Trackable Team

Build Status

Docs: comming soon | Subscribe URF Updates: @lelong37 | NuGet: goo.gl/WEn7Jm | Samples: https://goo.gl/MgC4tG

URF.Core Beta is Complete...!

URF.Core is feature complete and now has full parity with URF.NET (legacy .NET). URF.Core has gone through a complete rewrite with laser focus on Architecture, Design and Implementation as well as implementing top request for vNext, you can take a look at our URF.Core.Sample w/ ASP.NET Core Web API, OData, with full CRUD samples with Angular and Kendo UI.

Lightweight, Nano-Footprint

Staying faithful to (legacy) URF.NET of having a small footprint. URF.Core URF.Core (7 total classes) vs. URF.NET (12 total classes).

100% Extensible

We've made every implementation virtual therefore overridable for whatever teams/projects/developer use-cases as well as edge-cases.

IQuerable vs. IEnumerable

As as always, this is a religous debate between teams and the within the community. As with (legacy) URF.NET, we gave teams the option to opt into IQueryable or IEnumerable, and even both depending on your teams Architecture, Design & Implementation and style. As URF.NET and for teams that feel Repository Patterns that expose IQueryable as a leaky abstraction, simple use URF's IQuery API, which will give you all the Fluet features of IQueryable, however will return pure Entity or IEnumerable vs. using IQueryable, again URF.Core & URF.NET both support, so teams have the total freedom of decieding which 3 paths/options that makes the most sense for their team/project.

URF.Core sample and usage in ASP.NET Core Web API & OData

public class ProductsController : ODataController
{
    private readonly IProductService _productService;
    private readonly IUnitOfWork _unitOfWork;

    public ProductsController(
        IProductService productService,
        IUnitOfWork unitOfWork)
    {
        _productService = productService;
        _unitOfWork = unitOfWork;
    }

    [EnableQuery]
    public IQueryable<Products> Get()
    {
        return _productService.Queryable();
    }

    public async Task<IActionResult> Get([FromODataUri] int key)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var products = await _productService.Queryable().SingleOrDefaultAsync(m => m.ProductId == key);

        if (products == null)
        {
            return NotFound();
        }

        return Ok(products);
    }

    public async Task<IActionResult> Put(int key, [FromBody] Products products)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        if (key != products.ProductId)
        {
            return BadRequest();
        }

        products.TrackingState = TrackingState.Modified;

        try
        {
            await _unitOfWork.SaveChangesAsync();
        }
        catch (DbUpdateConcurrencyException)
        {
            if (!ProductsExists(key))
            {
                return NotFound();
            }
            else
            {
                throw;
            }
        }

        return NoContent();
    }

    public async Task<IActionResult> Post(Products products)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        _productService.Insert(products);
        await _unitOfWork.SaveChangesAsync();

        return Created(products);
    }

    public async Task<IActionResult> Delete(int key)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        var products = await _productService.Queryable().SingleOrDefaultAsync(m => m.ProductId == key);

        if (products == null)
        {
            return NotFound();
        }

        _productService.Delete(products);
        await _unitOfWork.SaveChangesAsync();

        return StatusCode((int) HttpStatusCode.NoContent);
    }

    private bool ProductsExists(int id)
    {
        return _productService.Queryable().Any(e => e.ProductId == id);
    }
}

Performance

URF.Core has been completly re-written, and everything is now completely task, async, await right out of the box. This way, team's will automatically get the best thread management and utilize and max out on asyncronous perf improvements.

About

Unit of Work & Repositories Framework - .NET Core, NET Standard, EntityFramework Core. 100% extensible & lightweight. Live demo: https://goo.gl/QpJVgd

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%