minimal .net core framework
NuGet Package (framework core)
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.
Example route with validation
Get("/api/v1/item/get", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
new ExistsInTable("item_guid", "items", "guid"),
});
if (errors.Count > 0) {
return HttpResponse.Errors(errors);
}
return HttpResponse.Item("item", new ItemTransformer().Transform(
ItemRepository.FindByGuid(Request.Query["item_guid"])
));
});
Example controller with middleware (check JWT token)
public class ItemCrudController : BaseController {
protected override IMiddleware[] Middleware() => new IMiddleware[] {
new JwtMiddleware()
};
public ItemCrudController() {
Post("/api/v1/item/create", _ => {
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] { });
if (errors.Count > 0) {
return HttpResponse.Errors(errors);
}
var item = ItemRepository.CreateAndGet((string) Request.Query["title"], (float) Request.Query["price"]);
return HttpResponse.Item("item", new ItemTransformer().Transform(item));
});
}
}
Example transformer
public class ItemTransformer : BaseTransformer {
public override JObject Transform(object obj) {
var item = (ItemModel) obj;
return new JObject {
["guid"] = item.guid,
["title"] = item.title,
["price"] = item.price,
};
}
}
Example: App/bin/Debug/netcoreapp2.2/config/config.json
Migrating
php vendor/bin/phinx migrate
- to migrate with default database (development)
php vendor/bin/phinx migrate -e testing
- to migrate with test database
dotnet App/bin/Debug/netcoreapp2.2/App.dll
Supported databases: PostgreSQL
Foundation of the framework is located in framework-base-core and loaded as submodule into Base project
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
Thank you for considering contributing to this repo. Feel free to submit any improvements / issues / refactoring / documentation etc.