GenericBizRunner 1.0.1.2

dotnet add package GenericBizRunner --version 1.0.1.2
NuGet\Install-Package GenericBizRunner -Version 1.0.1.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GenericBizRunner" Version="1.0.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GenericBizRunner --version 1.0.1.2
#r "nuget: GenericBizRunner, 1.0.1.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GenericBizRunner as a Cake Addin
#addin nuget:?package=GenericBizRunner&version=1.0.1.2

// Install GenericBizRunner as a Cake Tool
#tool nuget:?package=GenericBizRunner&version=1.0.1.2

GenericBizRunner

GenericBizRunner (modified from EfCore.GenericBizRunner) is a library to help build and run business logic with your choice of database access. Its aim is to totally isolate the business logic from other parts of the application, especially the user presentation/UI layers. It provides the following features:

  • A standard pattern for writing business logic, including helper classes.
  • An anti-corruption layer feature that act as a barrier between the business logic and the user presentation/UI layers.
  • When EF Core used for database accesses, the BizRunner handles the call to EF Core's SaveChanges, with optional validation.
  • A service, known as a BizRunner, that runs your business logic.
  • Very good use of Dependency Injection (DI), making calls to business logic very easy.

GenericBizRunner is available as a NuGet package.

Example of using GenericBizRunner in ASP.NET Core MVC

Here is some code taken from the ExampleWebApp (which you can run), from the OrdersController to give you an idea of what it looks like. Note that every business logic call is very similar, just different interfaces and DTO/ViewModel classes.

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult ChangeDelivery(WebChangeDeliveryDto dto,
    [FromServices]IActionService<IChangeDeliverAction> service)
{
    if (!ModelState.IsValid)
    {
        service.ResetDto(dto); //resets any dropdown list etc.
        return View(dto);
    }

    service.RunBizAction(dto);

    if (!service.Status.HasErrors)
    {
        //We copy the message from the business logic to show 
        return RedirectToAction("ConfirmOrder", "Orders", 
            new { dto.OrderId, message = service.Status.Message });
    }

    //Otherwise errors, so I need to redisplay the page to the user
    service.Status.CopyErrorsToModelState(ModelState, dto);
    service.ResetDto(dto); //resets any dropdown list etc.
    return View(dto); //redisplay the page, with the errors
}

Example of using GenericBizRunner in ASP.NET Core Web API

Here is a very simple example of creating a simple TodoItem taken from the EfCore.GenericService.AspNet ExampleWebApi application.

Note: The EfCore.GenericService.AspNetCore NuGet library contains the Response methods to convert the output of the business logic called by GenericBizRunner into a useful json response.

[ProducesResponseType(typeof (TodoItem), 201)] //Tells Swagger that the success status is 201, not 200
[HttpPost]
public ActionResult<TodoItem> Post(CreateTodoDto item, 
    [FromServices]IActionService<ICreateTodoBizLogic> service)
{
    var result = service.RunBizAction<TodoItem>(item);
    return service.Status.Response(this, 
        "GetSingleTodo", new { id = result?.Id }, result);
}

Why did I modify the library?

EfCore.GenericBizRunner is an awesome library that isolates the business logic so its easier to write and manage. However, it limit to only use Entity Framework Core for database accesses. So, modification required on EfCore.GenericBizRunner to allow other way of database accesses.

More information on the business logic pattern and library

The following links start with general descriptions and get deeper towards the end.

  • EfCore.GenericBizRunner, original library developed by Jon P Smith.
  • This article, which describes business pattern.
  • Chapter 4 of my book, which covers building of business logic using this pattern.
  • This article that describes the EfCore.GenericBizAction library with examples.
  • Project's Wiki, which has a quick start guide and deeper documentation.
  • Clone this repo, and run the ASP.NET Core application in it to see the business logic in action.
  • Read the example code, in this repo.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1.2 1,210 6/10/2020
1.0.1.1 418 6/3/2020
1.0.1 445 6/3/2020

- include documentation file in release