### Start SvelteKit Development Server Source: https://github.com/immediateplatform/immediate.dev/blob/main/README.md Commands to initiate the development server for the SvelteKit application. The first command starts the server, while the second additionally opens the application in a new browser tab. ```bash npm run dev ``` ```bash npm run dev -- --open ``` -------------------------------- ### Create New .NET Web Project Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md Initializes a new .NET web application named 'MyApp' and navigates into its directory. This step can be skipped if an existing project is available. ```bash dotnet new web -n MyApp cd MyApp ``` -------------------------------- ### Add ImmediatePlatform NuGet Packages Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md Adds the core `Immediate.Handlers` NuGet package as a dependency to the project. Optional packages like `Immediate.Validations`, `Immediate.Apis`, and `Immediate.Cache` can also be added for extended functionality. ```bash dotnet add package Immediate.Handlers # Optional: dotnet add package Immediate.Validations dotnet add package Immediate.Apis dotnet add package Immediate.Cache ``` -------------------------------- ### Register Immediate.Handlers with Dependency Injection Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md Configures the `Immediate.Handlers` services within the .NET dependency injection container by calling `builder.Services.AddHandlers()` in the `Program.cs` file, making handlers available throughout the application. ```csharp var builder = WebApplication.CreateBuilder(); builder.Services.AddHandlers(); var app = builder.Build(); app.Run(); ``` -------------------------------- ### Markdown Input for Component Transformation Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/kit-docs/README.md Provides examples of Markdown syntax that will be processed by the `kit-docs` plugin, demonstrating how images, blockquotes, and custom button containers are represented before transformation into Svelte components. ```markdown ![alt text](https://...) > This is a blockquote. !!!button ... !!! ``` -------------------------------- ### Define and Consume a Basic ImmediatePlatform Handler Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md Illustrates the creation of a simple `GetUserQuery` handler that accepts a user ID and returns a `User` record. It also demonstrates how to inject and consume this handler within another class to retrieve data, faking the user for simplicity. ```csharp [Handler] public static partial class GetUserQuery { public sealed record Query { public int UserId { get; set; } } public sealed record User(int UserId, string Username); private static ValueTask HandleAsync( Query query, CancellationToken token ) { var user = new User(query.UserId, "john"); return ValueTask.FromResult(user); } } ``` ```csharp public sealed class Consumer(GetUserQuery.Handler handler) { public async Task ConsumeAsync(CancellationToken token) { var response = await handler.HandleAsync(new("John"), token); // do something with response } } ``` -------------------------------- ### Expose ImmediatePlatform Handler as an API Endpoint Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...1]getting-started/[...2]quickstart/+page.md Demonstrates how to transform an existing `Immediate.Handlers` handler into a RESTful API endpoint using `Immediate.Apis`. This involves registering the API endpoints in `Program.cs` and applying the `[MapGet]` attribute to the handler class, making it accessible via HTTP. ```csharp var builder = WebApplication.CreateBuilder(); builder.Services.AddHandlers(); var app = builder.Build(); // here will be the name of your project app.MapMyAppEndpoints(); app.Run(); ``` ```csharp [Handler] [MapGet("/api/users/{UserId}")] public static partial class GetUserQuery { // ... } ``` -------------------------------- ### Creating a GET Endpoint with MapGet Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...4]Immediate.Apis/[...1]creating-endpoints/+page.md This C# code demonstrates how to transform an `Immediate.Handlers` handler into an HTTP GET endpoint by applying the `[MapGet("/users")]` attribute. It defines a `GetUsersQuery` class with a `HandleAsync` method responsible for retrieving a collection of users from a `UsersService`. ```C# [Handler] [MapGet("/users")] public static partial class GetUsersQuery { public record Query; private static ValueTask> HandleAsync( Query _, UsersService usersService, CancellationToken token) { return usersService.GetUsers(); } } ``` -------------------------------- ### Transformed Svelte Output from Markdown Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/kit-docs/README.md Shows the resulting Svelte component structure after the Markdown input (from the previous example) has been processed and transformed by the `kit-docs` plugin, illustrating how Markdown elements map to Svelte components like `Image`, `Blockquote`, and `Button`. ```svelte alt text
This is a blockquote.
``` -------------------------------- ### Mark Class for Validation with [Validate] and IValidationTarget Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...3]Immediate.Validation/[...1]creating-validators/+page.md Apply the `[Validate]` attribute to a class and implement the `IValidationTarget<>` interface to designate it as a target for Immediate.Validations. This setup enables the validation system to automatically process instances of the class, checking for defined validation rules. ```cs [Validate] public partial record Query : IValidationTarget; ``` -------------------------------- ### Customizing Endpoint OpenAPI Metadata Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...4]Immediate.Apis/[...2]customizing-endpoints/+page.md This example shows how to use the `CustomizeEndpoint` method within an Immediate.Apis handler to add additional OpenAPI metadata to an endpoint. This includes specifying expected response types (e.g., `200 OK`, `500 Internal Server Error`), indicating validation problems, and adding tags for better API documentation. ```C# [Handler] [MapGet("/users")] [Authorize(Policies.UserManagement)] public static partial class GetUsersQuery { internal static void CustomizeEndpoint(IEndpointConventionBuilder endpoint) => endpoint .Produces>(StatusCodes.Status200OK) .ProducesValidationProblem() .ProducesProblem(StatusCodes.Status500InternalServerError) .WithTags(nameof(User)); public record Query; private static ValueTask> HandleAsync( Query _, UsersService usersService, CancellationToken token) { return usersService.GetUsers(); } } ``` -------------------------------- ### Reference Other Properties/Methods in Validation Attributes using nameof() Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...3]Immediate.Validation/[...1]creating-validators/+page.md Illustrates how to reference static methods or properties within validation attributes using the `nameof()` operator, as attributes only accept constant expressions. This example uses `[Match(regex: nameof(AllDigitsRegex))]` to apply a regex defined by a separate method, enabling dynamic validation logic. ```cs [Validate] public partial record Query : IValidationTarget { [GeneratedRegex(@"^\d+$")] private static partial Regex AllDigitsRegex(); [Match(regex: nameof(AllDigitsRegex))] public required string Id { get; init; } } ``` -------------------------------- ### Build and Preview SvelteKit Production Application Source: https://github.com/immediateplatform/immediate.dev/blob/main/README.md Commands to compile the SvelteKit application into a production-ready build and to preview the generated static files. The deployment process utilizes `@sveltejs/adapter-static`. ```bash npm run build ``` ```bash npm run preview ``` -------------------------------- ### Benchmark Environment Configuration Summary Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...7]benchmarks/[...1]performance-comparisons/+page.md Provides a summary of the environment used for running the performance benchmarks, including the BenchmarkDotNet version, operating system, CPU specifications, and .NET SDK version. This information is crucial for understanding the context and reproducibility of the reported performance figures. ```text // * Summary * BenchmarkDotNet v0.14.0, Windows 11 (10.0.22631.4317/23H2/2023Update/SunValley3) 12th Gen Intel Core i7-12700H, 1 CPU, 20 logical and 14 physical cores .NET SDK 9.0.100 [Host] : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2 DefaultJob : .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2 ``` -------------------------------- ### Define a Command Handler for User Creation (C#) Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...2]Immediate.Handlers/[...1]creating-handlers/+page.md Shows how to define a command handler using the `[Handler]` attribute for creating a new user. It includes the `Command` record with an `Email` parameter and the `HandleAsync` method for processing the command. ```C# [Handler] public static partial class CreateUserCommand { public record Command(string Email); private static async ValueTask HandleAsync( Command command, UsersService usersService, CancellationToken token ) { await usersService.CreateUser(command.Email); } } ``` -------------------------------- ### Register Memory Cache with Dependency Injection Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...5]Immediate.Cache/[...1]creating-a-cache/+page.md This C# snippet demonstrates how to register the `IMemoryCache` service with the Dependency Injection container in your `Program.cs` file. This is a crucial prerequisite for utilizing `ApplicationCacheBase` as it relies on an `IMemoryCache` instance. ```cs services.AddMemoryCache(); ``` -------------------------------- ### Features/Todos/CreateTodo.cs - Initial API Endpoint Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...6]cookbook/[...2]fluent-validation/+page.md This C# code defines the initial `CreateTodo` handler, an Immediate.Handlers endpoint for creating new todo items. It includes the `Command` record for input and the `HandleAsync` method responsible for persisting the new todo to the database and returning a `Created` response. ```C# [Handler] [MapPost("/api/todos")] public static partial class CreateTodo { public sealed record Command { public string Name { get; init; } = null!; public string? Description { get; init; } } private static async ValueTask> HandleAsync( Command command, ExampleDbContext dbContext, CancellationToken ct ) { var todo = new Database.Models.Todo { Name = command.Name, Description = command.Description }; await dbContext.Todos.AddAsync(todo, cancellationToken: ct); await dbContext.SaveChangesAsync(ct); return TypedResults.Created($"/api/todos/{todo.Id}", todo.ToDto()); } } ``` -------------------------------- ### Consume a Handler via IHandler Interface (C#) Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...2]Immediate.Handlers/[...1]creating-handlers/+page.md Illustrates how to consume a handler through its `IHandler` interface, providing a decoupled way to interact with handlers, especially when direct references are not feasible. ```C# public class Consumer(IHandler> handler) { public async Task Consumer(CancellationToken token) { var response = await handler.HandleAsync(new(), token); // do something with response } } ``` -------------------------------- ### terminal - Add FluentValidation Packages Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...6]cookbook/[...2]fluent-validation/+page.md These Bash commands are used to add the necessary FluentValidation NuGet packages to the project. `FluentValidation` provides the core validation framework, and `FluentValidation.DependencyInjectionExtensions` facilitates its integration with .NET's dependency injection system. ```Bash dotnet add package FluentValidation dotnet add package FluentValidation.DependencyInjectionExtensions ``` -------------------------------- ### Consume a Generated Query Handler (C#) Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/routes/docs/[...2]Immediate.Handlers/[...1]creating-handlers/+page.md Demonstrates how a consumer class can inject and use the automatically generated handler (`GetUsersQuery.Handler`) to execute a query and retrieve a response. ```C# public class Consumer(GetUsersQuery.Handler handler) { public async Task Consumer(CancellationToken token) { var response = await handler.HandleAsync(new(), token); // do something with response } } ``` -------------------------------- ### Using Global Svelte Components in Markdown Source: https://github.com/immediateplatform/immediate.dev/blob/main/src/kit-docs/README.md Illustrates how to integrate and use global Svelte components, such as a `Button`, directly within Markdown files. It shows both direct component usage and how to leverage Markdown container syntax to pass props and dynamic slot elements. ```svelte