|
| 1 | +# Initium — Service Core Foundation |
| 2 | + |
| 3 | +[](https://github.com/imclint21/Initium/actions/workflows/publish.yml) |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +Initium is a library for simplifying .NET API development, offering standardized service operations, flexible routing, and seamless chaining of service results for cleaner and more maintainable code. |
| 10 | + |
| 11 | +- **Streamlined API Controllers**: Simplifies response handling with attributes like `[ApiResponse]`, providing clear and consistent HTTP status documentation. |
| 12 | +- **Centralized Result Management**: `ServiceResult` enables clear success or failure status, making error handling and conditional logic seamless. |
| 13 | +- **Exception Handling Made Easy**: `ApiException` provides a straightforward way to handle specific HTTP error codes, improving code clarity. |
| 14 | +- **Result Chaining**: Methods return `ServiceResult` or typed results, allowing for intuitive chaining and cleaner service logic. |
| 15 | +- **Enhanced Maintainability**: Standardized patterns reduce boilerplate code, making APIs easier to build, understand, and maintain. |
| 16 | + |
| 17 | +## Getting Started |
| 18 | + |
| 19 | +To get started with Initium, just add the package using NuGet: |
| 20 | + |
| 21 | +```bash |
| 22 | +dotnet add package Initium |
| 23 | +``` |
| 24 | + |
| 25 | +## How it Works? |
| 26 | + |
| 27 | +Here's how to create a controller : |
| 28 | + |
| 29 | +```csharp |
| 30 | +public class CoffeeController(CoffeeService service) : ApiController |
| 31 | +{ |
| 32 | + [HttpPost] |
| 33 | + [ApiResponse(200, "Coffee prepared successfully.")] |
| 34 | + [ApiResponse(400, "An error occurred during the preparation process.")] |
| 35 | + public ActionResult PrepareCoffee() => service.PrepareCoffee(); |
| 36 | +} |
| 37 | +``` |
| 38 | +And here's how to create an action in a service, each function returns a `ServiceResult`, and can be chained. |
| 39 | + |
| 40 | +```csharp |
| 41 | +public class CoffeeService |
| 42 | +{ |
| 43 | + public ServiceResult DoSomething() |
| 44 | + { |
| 45 | + return ServiceResult.Error("Something happened!", HttpStatusCode.Conflict); |
| 46 | + } |
| 47 | + |
| 48 | + public ServiceResult PrepareCoffee() |
| 49 | + { |
| 50 | + var doSomethingResult = DoSomething(); |
| 51 | + if (doSomethingResult == false) return doSomethingResult; |
| 52 | + |
| 53 | + return ServiceResult.Ok("The coffee is now DONE!"); |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +## Contribute to Initium |
| 59 | + |
| 60 | +See [CONTRIBUTING.md](CONTRIBUTING.md) for best practices and instructions on setting up your development environment to work on Initium. |
0 commit comments