-
Notifications
You must be signed in to change notification settings - Fork 0
Business Logic
The business logic is divided into the following namespaces:
Namespace | Contents |
---|---|
FlightRecorder.BusinessLogic.Api | External API integrations |
FlightRecorder.BusinessLogic.Config | Common application settings reader |
FlightRecorder.BusinessLogic.Database | Logic for reading from/writing to the database |
FlightRecorder.BusinessLogic.Factory | Factory class for accessing the database logic |
FlightRecorder.BusinessLogic.Logging | Logging implementation |
FlightRecorder.DataExchange.Export | CSV-format data export logic |
FlightRecorder.DataExchange.Import | CSV-format data import logic |
The logic for accessing the flight recorder data is implemented as a set of management classes, one per entity type, in the FlightRecorder.BusinessLogic.Database namespace.
These classes are marked as internal and for consuming applications the database logic is accessed using an instance of the Flight Recorder "factory" class.
The FlightRecorderFactory class in the FlightRecorder.BusinessLogic.Factory namespace implements a facade that exposes the database management classes via the interfaces they implement and co-ordinates their activity.
The factory is the sole entry point for applications wishing to use the business logic to read from/write to the database.
Note that other logic - such as the external API integrations and data exchange logic - are not fronted by the factory class.
- Reference the FlightRecorder.Entities library
- Reference the FlightRecorder.BusinessLogic library
- Reference the FlightRecorder.Data library
- Create a database context
- Create a Flight Recorder Factory
The following are the using statements:
using FlightRecorder.BusinessLogic.Factory;
using FlightRecorder.Data;
using FlightRecorder.Entities.Db;
The following code snippet creates the factory:
FlightRecorderDbContext context = new FlightRecorderDbContextFactory().CreateInMemoryDbContext();
FlightRecorderFactory factory = new FlightRecorderFactory(context);
Depending on your application, the context may be injected rather than being created using the context factory.
By way of example, the following reads and displays a list of the second page of manufacturers from the database using a page size of 10:
var manufacturers = await factory.Manufacturers.List(null, 2, 10).ToListAsync();
foreach (var manufacturer in manufacturers)
{
Console.WriteLine(manufacturer.Name);
}
Again, by way of example, the following adds a new manufacturer to the database:
var manufacturer = await factory.Manufacturers.AddAsync("Airbus");