Skip to content

ak-app/coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version: 1.0 Release .NET Core Desktop codecov License: GPL v3

C# library example

Program Layout

Main Add Update
FormMain FormData FormData

An empty template that includes the forms above can be downloaded here. A full running example can be downloaded here.


Example program

The standard example program uses a list as data store. It can not be adaptet like the following program with abstraction. It can be found in the LibraryManagement solution under _FormsNoAbstraction.


Example program with abstraction

The example program with abstraction includes a modular IDataAccess which is implemented by different libraries as BookDataAccess with:

  1. Book List
  2. SQLite Database
  3. EF Core
  4. File

The abstract ValidateBookDataAccess library implements the Validation of the Book objects. It can be found in the LibraryManagement solution under LibraryManagement.Access.

BookDataAccess as List

Implements a simple list in backend and is designed for testing purpose.

_bookDataAccess = new Access.Memory.BookDataAccess();

BookDataAccess with Database

Data is saved in a SQLite database either with EFCore or with raw SQL. Can be used within every database that inherits from DbConnection and DbCommand (e.g. mSQL, MySQL, mariaDB, ...).

IConfiguration config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json")
    .Build();
// -> With native SQL (sqlite, mariadb, mysql, msql)
_connection = new SqliteConnection(config.GetConnectionString("SQLiteConnectionString"));
_bookDataAccess = new Access.Db.BookDataAccess(_connection);
// -> With EFCore
_connection = new SqliteConnection(config.GetConnectionString("SQLiteCoreConnectionString"));
DbContextOptionsBuilder builder = new DbContextOptionsBuilder<Access.Core.DataContext>()
    .UseSqlite(_connection);
_bookDataAccess = new Access.Core.BookDataAccess(new Access.Core.DataContext(builder.Options));

BookDataAccess with File

Implements a file reader/writer for handling the list of books

_bookDataAccess = new Access.File.BookDataAccess("Books.dat");

Global class diagram

Diagram


R. GÄCHTER