Skip to content

Repository files navigation

Micron

TravisCINuGet Package (framework core)

Description

Minimal .net core framework based on three tier architecture, can be used as template for building API's

I've built this framework mostly for myself with all needed features out of the box, but this foundation can be more modular to have more potential use cases.

Features

Example route with validation

Get("/api/v1/item/get", _ =>{varerrors=ValidationProcessor.Process(Request,newIValidatorRule[]{newExistsInTable("item_guid","items","guid"),});if(errors.Count>0){returnHttpResponse.Errors(errors);}returnHttpResponse.Item("item",newItemTransformer().Transform(ItemRepository.FindByGuid(Request.Query["item_guid"])));});

Example controller with middleware (check JWT token)

publicclassItemCrudController:BaseController{protectedoverrideIMiddleware[]Middleware()=>newIMiddleware[]{newJwtMiddleware()};publicItemCrudController(){Post("/api/v1/item/create", _ =>{varerrors=ValidationProcessor.Process(Request,newIValidatorRule[]{});if(errors.Count>0){returnHttpResponse.Errors(errors);}varitem=ItemRepository.CreateAndGet((string)Request.Query["title"],(float)Request.Query["price"]);returnHttpResponse.Item("item",newItemTransformer().Transform(item));});}}

Example transformer

publicclassItemTransformer:BaseTransformer{publicoverrideJObjectTransform(objectobj){varitem=(ItemModel)obj;returnnewJObject{["guid"]=item.guid,["title"]=item.title,["price"]=item.price,};}}

Set up:

  1. restore nuget packages
  2. build project
  3. copy config.example.json into:
  • For main app
  • App/bin/%BUILD_TYPE%/netcoreapp2.2/config/config.json
  • For unit tests
  • Tests/bin/%BUILD_TYPE%/netcoreapp2.2/config/config.json

Example: App/bin/Debug/netcoreapp2.2/config/config.json

  1. edit config files - fill database name / user / etc.

Migrating

  1. copy migrations/phinx.example.yml to migrations/phinx.yml
  2. edit phinx.yml - fill database user / password etc.
  3. install php & composer dependencies from migrations/composer.json
  4. run migrations (in migrations folder):

php vendor/bin/phinx migrate - to migrate with default database (development)

php vendor/bin/phinx migrate -e testing - to migrate with test database


  1. Run it! via dotnet dotnet App/bin/Debug/netcoreapp2.2/App.dll

Tech summary:

Supported databases: PostgreSQL


System requirements:

  • .net core > 2.2
  • database (PostgreSql only)
  • PHP > 7.0 (for migrations)

Project structure:

Foundation of the framework is located in framework-base-core and loaded as submodule into Base project


Used tools:

Database:

Building & running project

You should be able to build with dotnet build and run app via for example: dotnet App/bin/Debug/netcoreapp2.2/App.dll

Contribution:

Thank you for considering contributing to this repo. Feel free to submit any improvements / issues / refactoring / documentation etc.

Releases

Packages

Used by

Contributors

Languages