{"id":16674827,"url":"https://github.com/odan/aspnet-api","last_synced_at":"2026-04-20T20:03:58.804Z","repository":{"id":71945031,"uuid":"579028213","full_name":"odan/aspnet-api","owner":"odan","description":"A minimal ASP.NET Core API","archived":false,"fork":false,"pushed_at":"2024-04-05T10:58:31.000Z","size":145,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T20:48:44.424Z","etag":null,"topics":["architecture","aspnet","aspnet-web-api","aspnetcore","charp","clean-architecture","ddd","mysql","skeleton","xunit"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/odan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-16T13:32:47.000Z","updated_at":"2024-03-02T03:19:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"0c72d979-82b9-4c4f-99eb-99ae37e96c3d","html_url":"https://github.com/odan/aspnet-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odan%2Faspnet-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odan%2Faspnet-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odan%2Faspnet-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/odan%2Faspnet-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/odan","download_url":"https://codeload.github.com/odan/aspnet-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243331693,"owners_count":20274317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["architecture","aspnet","aspnet-web-api","aspnetcore","charp","clean-architecture","ddd","mysql","skeleton","xunit"],"created_at":"2024-10-12T12:44:31.378Z","updated_at":"2026-04-20T20:03:58.798Z","avatar_url":"https://github.com/odan.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aspnet-api\n\nA minimal ASP.NET Core API\n\n## Requirements\n\n* [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)\n* A MySQL database\n\n## Features\n\n* OpenAPI\n* Dependency injection container\n* Single Action Controllers, Services and Repositories\n* Environment specific configuration\n* 12-Factor `.env` configuration loader (for sensitive data)\n* EF Core + MySQL\n* Database transaction handling\n* Input validation (Attribute based and custom validators)\n* ValidationException middleware\n* Localization (NGettext)\n* Context specific logging (Serilog)\n* File based error logging\n* Continuous integration (CI) workflow with GitHub Actions\n* Database migrations (DbUp)\n\n**Testing**\n\n* XUnit tests\n* HTTP endpoint tests (using a test database)\n* Fluent assertions for log messages\n\n*Todo*\n\n* Fluent assertions for database tests \n* Authentication (BasicAuth)\n* Build script\n\n## Installation\n\nRun the following command to create a new project:\n\n```\ngit clone https://github.com/odan/aspnet-api.git --depth 1 {my-app-name}\ncd {my-app-name}\n```\n\nReplace `{my-app-name}` with the desired name for your project. \n\n\nCreate a new MySQL / MariaDB database.\n\n```sql\nCREATE DATABASE `my_api` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; \n```\n\nModify the database name accordingly.\n\nCreate a `.env` file in the `MyApi` directory:\n\n```env\nConnectionStrings__Default=server=127.0.0.1;uid=root;pwd=;database=my_api\n```\n\nModify the database and credentials accordingly.\n\n## Migrations\n\nInstall EF tooling (once):\n\n```\ndotnet tool install --global dotnet-ef\n```\n\n### Add migration\n\nMake table changes in MyApi.Infrastructure.Persistence.Configurations, then generate a new migration with:\n\n```\ndotnet ef migrations add MyMigrationName -p MyApi.Infrastructure -s MyApi.Api\n```\n\n###  Apply migration\n\n```\ndotnet ef database update -p MyApi.Infrastructure -s MyApi.Api\n```\n\n## Commands\n\nTo build and run the application in debug mode, run:\n\n```\ndotnet run\n```\n\nor\n\n```\ndotnet watch run\n```\n\nRunning a release build:\n\n```\ndotnet run --configuration Release\n```\n\nBuild a project and its dependencies:\n\n```\ndotnet build\n```\n\nBuilding a project and its dependencies using Release configuration:\n\n```\ndotnet build --configuration Release\n```\n\nCleaning the bin and obj directories:\n\n```\ndotnet clean\n```\n\nClean and build:\n\n```\ndotnet rebuild\n```\n\nPublish:\n\n```\ndotnet publish\n```\n\n**Code styles**\n\nInstall the `dotnet-format ` package:\n\n```\ndotnet tool install --global dotnet-format \n```\n\nChecking code styles:\n\n```\ndotnet format --verify-no-changes\n```\n\nFixing code styles:\n\n```\ndotnet format -v d\n```\n\n## Translations\n\nDeclare the `IStringLocalizer\u003cT\u003e` interface \nwhere you need to translate messages.\n\n**Example**\n\n```csharp\npublic class Example\n{\n    private readonly IStringLocalizer\u003cExample\u003e _localizer;\n\n    public Example(IStringLocalizer\u003cExample\u003e localizer)\n    {\n        _localizer = localizer;\n    }\n\n    // ...\n}\n```\n\n### Translation Usage\n\nThe default and source language is english.\n\nTranslating a simple message:\n\n```cs\nstring text = _localizer.GetString(\"Hello, World!\");\n\n// Output: Hallo, Welt!\n```\n\nTranslating a message with placeholder(s):\n\n```cs\nstring text2 = _localizer.GetString(\"The user {0} logged in\", \"sally\");\n\n// Output: Der Benutzer sally hat sich eingeloggt\n```\n\n### Creating a new translation file\n\n* Open Poedit and create a new PO translation file in the project `Resources` directory.\n* The filename must be the same as the culture name, e.g. `de-DE.po`.\n* Open the menu `Translations` \u003e `Settings`\n* Change the PO language, e.g. `German`\n* Add `_localizer.GetString` as sources keyword.\n* Add the source paths with your project CS files.\n* Save the file and click `Update from source` to parse for new translations.\n* Translate the messages and save the file to generate the MO file, e.g. `de-DE.mo`.\n\n### Changing the language\n\nYou can change the language during the request by setting the CurrentCulture\nas follows:\n\n```csharp\nusing using System.Globalization;\n// ...\n\nvar culture = new CultureInfo(\"de-DE\");\nThread.CurrentThread.CurrentCulture = culture;\nThread.CurrentThread.CurrentUICulture = culture;\n```\n\nThe `LocalizationMiddleware` detects the user language using the HTTP request\n`Accept-Language` header value. If this header contains a valid code, the \nCurrentCulture will be switched automatically.\n\n## Testing\n\nCreate a local **test** database for xUnit.\n\n```sql\nCREATE DATABASE `my_api_test` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; \n```\n\nCreate a `.env` file in the `MyApi.Tests` directory:\n\n```env\nConnectionStrings__Default=server=127.0.0.1;uid=root;pwd=;database=my_api_test\n```\n\nModify the database and credentials accordingly.\n\nTo start the test suite, run:\n\n```\ndotnet test\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodan%2Faspnet-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fodan%2Faspnet-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fodan%2Faspnet-api/lists"}