-
Notifications
You must be signed in to change notification settings - Fork 57
QUICK START guide
This details all the steps you need to do to use the GenericBizRunner library.
NOTE: There is a much longer article called A library to run your business logic when using Entity Framework Core which gives a more detailed account of how to use the GenericBizRunner library, with examples.
You can use any architecture you like, but in this quick start page I will refer to project/assembly by the names shown in this diagram

-
EfCore.GenericBizRunner in the following projects/assemblies:
- Bizlogic: The project/assembly(s) that hold your business logic.
- Presentation: The ASP.NET Core project/assembly (for setup).
- ServiceLayer: The project/assembly(s) where you are going to create presentation-focused DTOs (see Anti-corruption feature).
- Presentation: You most likely will be using dependency injection to link the projects/assemblies. You need to register GenericBizRunner.
Your business logic has to:
- Implement the
IBizActionStatusinterface, which you can do by inheriting theBizActionStatusabstract class - It should have an interface for DI, and that interface should inherit from one of the 12 GenericBizRunner's
IGenericAction???interface (see What your interface looks like).
See Writing your Business Logic for more.
Here are the steps for registering GenericBizRunner with .NET Core's DI provider. Typically this is done at startup - in an ASP.NET Core applications your code would go in the ConfigureServices method in the Startup class (see Startup class in the ExampleWebApp for example).
- Register GenericBizRunner, which will also scan the assemblies that contain your GenericBizRunner DTOs. There are a few options, but here is a typical format.
services.RegisterBizRunnerWithDtoScans<YourDbContext>(
Assembly.GetAssembly(typeof(OneOfYourBizDTO)));- Register your business logic. I recommend using the library NetCore.AutoRegisterDi (see link to example code above).
See the Setup Wiki page for more. NOTE: GenericBizRunner can be used in a non-DI situation too.
In places where you can inject via DI then if you wanted to run an synchronous business logic who's interface was IMyBizLogic, then you would use this signature: IActionService<IMyBizLogic>.
For instance, if you were using an ASP.NET Core Action method inside a controller you could inject the BizRunner service using the [FromService] in the actions' parameter, e.g.
public IActionResult PlaceOrder(PlaceOrderInDto dto,
[FromServices]IActionService<IMyBizLogic> service)Assuming you have a variable called service with an instance of the BizRunner service, as setup by the last step, then you can run it by calling.
var order = service.RunBizAction<MyOutputClass>(myInputDtoInstance);Or for async
var order = await service.RunBizActionAsync<MyOutputClass>(myInputDtoInstance);Note: there are different versions of the RunBizAction depending on whether the business logic has an input and/or an output. There are also async versions of the BizRunner service, e.g. IActionServiceAsync<IMyBizLogicAsync>.
You can find out if the business logic ran successfully by testing the service.Status.HasErrors boolean property. You can access any errors via the service.Status.Errors property. if the business logic ran successfully the service.Status.Message will contain a sensible success message.
See Running your business logic for more.