magic.library 15.5.1

.NET 6.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package magic.library --version 15.5.1
NuGet\Install-Package magic.library -Version 15.5.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="magic.library" Version="15.5.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add magic.library --version 15.5.1
#r "nuget: magic.library, 15.5.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install magic.library as a Cake Addin
#addin nuget:?package=magic.library&version=15.5.1

// Install magic.library as a Cake Tool
#tool nuget:?package=magic.library&version=15.5.1

magic.library - Tying Magic together

This project helps you to wire up everything related to Magic. Normally you'd use it simply like the following from your startup class in your .Net 6 Web API project.

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using magic.library;

namespace magic.backend
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            // Initializing Magic.
            services.AddMagic(Configuration);
        }

        public void Configure(IApplicationBuilder app)
        {
            // Initializing Magic.
            app.UseMagic(Configuration);
        }
    }
}

However, you can also take more control over how things are actually wired up, by instead of using the "do all methods" called AddMagic and UseMagic, invoke some of the specialized initialization methods, you can find below.

  • IServiceCollection.AddMagicCaching
  • IServiceCollection.AddMagicHttp
  • IServiceCollection.AddMagicLogging
  • IServiceCollection.AddMagicSignals
  • IServiceCollection.AddMagicExceptions
  • IServiceCollection.AddMagicEndpoints
  • IServiceCollection.AddMagicAuthorization
  • IServiceCollection.AddMagicFileServices
  • IServiceCollection.AddMagicFileServices
  • IServiceCollection.AddMagicConfiguration
  • IServiceCollection.AddMagicScheduler
  • IServiceCollection.AddMagicMail
  • IServiceCollection.AddMagicLambda
  • IServiceCollection.AddMagicSockets

The above methods is basically what the AddMagic method actually does, and they're extension methods of IServiceCollection, that can be found in the magic.library namespace. Similar alternatives to UseMagic can be found below.

  • IApplicationBuilder.UseMagicExceptions
  • IApplicationBuilder.UseMagicStartupFiles
  • IApplicationBuilder.UseMagicScheduler
  • IApplicationBuilder.UseMagicCors

If you use these methods instead of the "do all methods", your motivation would probably be to replace one of these methods with your own implementation, to exchange the default wiring, by (for instance) using a "virtual database based file system" by creating your own service implementation of for instance IFileService from "magic.lambda.io", or use a different logging provider than the default, etc. If you wish to do this, you'd probably benefit from looking at what the default implementation of your method does, to understand the requirements from your method. Doing this is very powerful, and allows you to change the way the system behaves by default - But is also definitely considered an "advanced exercise".

Exceptions handlers

Magic allows you to provide a custom exceptions handler on a per folder level. This overrides the default exception logic with a custom exception handler expected to be named "exceptions.hl" and found within the folder hierarchy where an HTTP invocation is resolved. For instance, if you wish to create your own exception handler for a specific module called "foo", you can create an exception handler file called "/files/modules/foo/exceptions.hl", and expect this file to be invoked every time an unhandled exception occurs, anywhere inside of your "foo" folder. This allows you to transform an unhandled exception, such as for instance localising it or customising it in any ways. Your custom exception handler will be invoked with the following arguments.

  • [message] - The exception error message
  • [path] - The URL that triggered the exception
  • [field] - If the exception that was thrown declared a field, this argument will contain the name of the field
  • [status] - If the exception that was thrown declared a status code, this argument will contain the status code
  • [public] - If the exception that was thrown wants to propagate to the client this will be true

You can return a "transformed" exception from your exception handler, returning the following arguments, that will end up becoming the response object returned to the client.

  • [message] - Message to return as JSON to client
  • [field] - Field to return as JSON to client
  • [status] - Status code to decorate your HTTP response with

The default exception handler can be found in "/files/exceptions.hl", which will be invoked if no custom exception handler is declared further down in your folder hierarchy.

Project website for magic.lambda.library

The source code for this repository can be found at github.com/polterguy/magic.library, and you can provide feedback, provide bug reports, etc at the same place.

  • Build status
  • Quality Gate Status
  • Bugs
  • Code Smells
  • Duplicated Lines (%)
  • Lines of Code
  • Maintainability Rating
  • Reliability Rating
  • Security Rating
  • Technical Debt
  • Vulnerabilities
Product Versions
.NET net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
15.9.1 131 3/27/2023
15.9.0 176 3/24/2023
15.8.2 202 3/20/2023
15.7.0 93 3/6/2023
15.5.20 415 2/23/2023
15.5.13 246 2/13/2023
15.5.9 139 2/11/2023
15.5.2 163 2/5/2023
15.5.1 154 2/3/2023
15.5.0 214 1/28/2023
15.2.0 347 1/18/2023
15.1.0 839 12/28/2022
14.5.7 391 12/13/2022
14.5.5 482 12/6/2022
14.5.1 334 11/23/2022
14.5.0 290 11/18/2022
14.4.5 345 10/22/2022
14.4.2 277 10/22/2022
14.4.1 273 10/22/2022
14.4.0 302 10/17/2022
14.3.9 305 10/13/2022
14.3.6 318 10/7/2022
14.3.2 329 9/18/2022
14.3.1 469 9/12/2022
14.3.0 317 9/10/2022
14.1.3 602 8/7/2022
14.1.2 331 8/7/2022
14.1.1 323 8/7/2022
14.0.14 374 7/26/2022
14.0.12 361 7/24/2022
14.0.11 345 7/23/2022
14.0.10 355 7/23/2022
14.0.9 358 7/23/2022
14.0.8 441 7/17/2022
14.0.5 496 7/11/2022
14.0.4 442 7/7/2022
14.0.3 402 7/2/2022
14.0.2 359 7/2/2022
14.0.1 391 7/2/2022
14.0.0 382 6/25/2022
13.4.28 383 6/11/2022
13.4.25 499 6/9/2022
13.4.24 384 6/9/2022
13.4.19 434 6/8/2022
13.4.3 395 6/6/2022
13.4.2 454 6/4/2022
13.4.0 469 5/31/2022
13.3.8 444 5/19/2022
13.3.7 399 5/18/2022
13.3.6 452 5/14/2022
13.3.4 525 5/9/2022
13.3.1 477 5/1/2022
13.3.0 416 5/1/2022
13.2.2 471 4/25/2022
13.2.1 420 4/25/2022
13.2.0 466 4/21/2022
13.1.1 461 4/20/2022
13.1.0 531 4/7/2022
13.0.0 473 4/5/2022
12.0.3 598 3/14/2022
11.0.7 463 3/11/2022
11.0.5 531 3/2/2022
11.0.4 485 2/22/2022
11.0.3 498 2/9/2022
11.0.2 537 2/6/2022
11.0.1 521 2/5/2022
10.0.21 494 1/28/2022
10.0.20 505 1/27/2022
10.0.19 499 1/23/2022
10.0.18 478 1/17/2022
10.0.17 485 1/14/2022
10.0.16 380 1/2/2022
10.0.15 451 12/31/2021
10.0.14 460 12/28/2021
10.0.13 527 12/23/2021
10.0.11 316 12/23/2021
10.0.10 319 12/22/2021
10.0.9 495 12/22/2021
10.0.8 346 12/22/2021
10.0.7 495 12/22/2021
10.0.6 397 12/19/2021
10.0.5 503 12/18/2021
10.0.3 289 12/16/2021
10.0.2 360 12/14/2021
10.0.1 271 12/13/2021
10.0.0 313 12/6/2021
9.9.9 1,063 11/29/2021
9.9.6 4,553 11/24/2021
9.9.5 298 11/23/2021
9.9.4 610 11/21/2021
9.9.3 366 11/9/2021
9.9.2 387 11/4/2021
9.9.0 507 10/30/2021
9.8.9 520 10/29/2021
9.8.7 423 10/27/2021
9.8.6 407 10/27/2021
9.8.5 519 10/26/2021
9.8.4 450 10/25/2021
9.8.3 543 10/24/2021
9.8.1 404 10/21/2021
9.8.0 491 10/20/2021
9.7.9 422 10/20/2021
9.7.8 409 10/19/2021
9.7.7 637 10/17/2021
9.7.6 552 10/17/2021
9.7.5 421 10/14/2021
9.7.1 380 10/14/2021
9.7.0 445 10/9/2021
9.6.8 438 8/30/2021
9.6.7 409 8/26/2021
9.6.6 551 8/14/2021
9.6.5 648 8/11/2021
9.6.4 438 8/10/2021
9.6.3 440 8/9/2021
9.6.2 418 8/8/2021
9.6.1 389 8/8/2021
9.5.9 563 8/5/2021
9.5.8 559 8/4/2021
9.5.3 435 7/20/2021
9.5.0 763 7/9/2021
9.4.5 457 6/29/2021
9.4.4 587 6/29/2021
9.4.0 420 6/24/2021
9.3.7 443 6/21/2021
9.3.6 484 6/21/2021
9.3.5 620 6/18/2021
9.3.4 539 6/18/2021
9.2.5 602 6/7/2021
9.2.4 509 6/6/2021
9.2.3 456 6/6/2021
9.2.2 404 6/4/2021
9.2.1 617 6/1/2021
9.2.0 588 5/26/2021
9.1.9 384 5/5/2021
9.1.8 539 5/5/2021
9.1.7 394 5/3/2021
9.1.4 417 4/21/2021
9.1.2 403 4/18/2021
9.1.1 365 4/15/2021
9.1.0 415 4/14/2021
9.0.1 516 4/12/2021
9.0.0 423 4/5/2021
8.9.92 929 3/30/2021
8.9.4 964 3/26/2021
8.9.3 965 3/19/2021
8.9.2 958 1/29/2021
8.9.1 1,040 1/24/2021
8.9.0 1,099 1/22/2021
8.7.1 1,387 11/15/2020
8.7.0 1,079 11/15/2020
8.6.9 1,035 11/8/2020
8.6.7 1,011 11/4/2020
8.6.6 1,089 11/2/2020
8.6.5 1,056 11/1/2020
8.6.3 1,060 10/30/2020
8.6.2 974 10/30/2020
8.6.1 1,080 10/29/2020
8.6.0 1,007 10/28/2020
8.5.1 1,008 10/26/2020
8.5.0 1,000 10/23/2020
8.4.6 1,197 10/20/2020
8.4.5 1,036 10/18/2020
8.4.4 1,063 10/17/2020
8.4.3 1,034 10/16/2020
8.4.2 1,022 10/16/2020
8.4.1 1,008 10/15/2020
8.4.0 1,082 10/13/2020
8.3.3 1,011 10/11/2020
8.3.2 1,073 10/8/2020
8.3.1 1,075 10/5/2020
8.3.0 1,038 10/3/2020
8.2.3 968 10/1/2020
8.2.2 1,217 9/26/2020
8.2.1 1,097 9/25/2020
8.2.0 1,132 9/25/2020
8.1.25 1,027 9/24/2020
8.1.24 1,054 9/23/2020
8.1.23 1,018 9/23/2020
8.1.22 1,064 9/21/2020
8.1.21 1,112 9/15/2020
8.1.20 1,109 9/14/2020
8.1.19 1,052 9/13/2020
8.1.18 1,051 9/13/2020
8.1.17 1,107 9/13/2020
8.1.16 1,085 9/13/2020
8.1.15 1,009 9/12/2020
8.1.13 939 9/11/2020
8.1.12 1,059 9/11/2020
8.1.11 1,040 9/11/2020
8.1.10 1,088 9/6/2020
8.1.9 1,069 9/3/2020
8.1.8 1,104 9/2/2020
8.1.7 963 8/28/2020
8.1.4 987 8/25/2020
8.1.3 1,098 8/18/2020
8.1.2 957 8/16/2020
8.1.1 1,035 8/15/2020
8.0.3 1,028 8/11/2020
8.0.2 1,055 8/7/2020
8.0.1 1,028 8/7/2020
8.0.0 1,022 8/7/2020
7.0.1 1,123 6/28/2020
7.0.0 1,116 6/28/2020
5.0.10 1,087 5/31/2020
5.0.9 1,144 5/30/2020
5.0.8 1,053 5/29/2020
5.0.7 1,029 5/29/2020
5.0.5 1,143 2/27/2020
5.0.4 1,059 2/26/2020
5.0.3 1,062 2/26/2020
5.0.2 1,081 2/25/2020
5.0.1 988 2/25/2020
5.0.0 1,078 2/25/2020
4.1.5 1,043 2/23/2020
4.1.4 1,140 2/23/2020
4.1.3 1,080 2/22/2020
4.1.2 1,060 2/22/2020
4.1.1 1,050 2/21/2020
4.1.0 1,085 2/21/2020
4.0.9 1,153 2/7/2020
4.0.8 986 2/7/2020
4.0.7 1,017 2/7/2020
4.0.5 1,016 1/28/2020
4.0.4 1,143 1/27/2020
4.0.3 1,062 1/27/2020
4.0.2 1,145 1/16/2020
4.0.1 1,161 1/11/2020
4.0.0 1,117 1/5/2020
3.1.7 1,181 12/17/2019
3.1.6 1,102 12/12/2019
3.1.5 1,083 12/12/2019
3.1.4 1,101 12/5/2019
3.1.3 1,125 12/4/2019
3.1.2 1,137 11/30/2019
3.1.1 1,295 11/26/2019
3.1.0 1,123 11/10/2019
3.0.4 952 11/1/2019
3.0.3 1,083 10/28/2019
3.0.2 1,138 10/28/2019
3.0.1 1,127 10/26/2019
3.0.0 964 10/23/2019
2.1.4 762 10/21/2019
2.1.3 1,088 10/21/2019
2.1.2 1,173 10/21/2019
2.1.1 1,055 10/19/2019
2.1.0 1,124 10/19/2019
2.0.9 869 10/18/2019
2.0.8 1,112 10/18/2019
2.0.7 873 10/18/2019
2.0.6 866 10/18/2019
2.0.5 905 10/18/2019
2.0.4 874 10/17/2019
2.0.3 963 10/16/2019
2.0.2 971 10/15/2019
2.0.1 1,003 10/14/2019
2.0.0 741 10/13/2019
1.1.7 1,119 10/11/2019
1.1.6 1,098 10/11/2019