Magic Cloud

An Open Source Application Generator


Magic Library

Helper project for Magic, to wire up everything and initialize Magic.

This project will help you to wire up everything related to Magic. Normally you’d use it simply like the following from your startup class in your .Net Core Web API project.

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

namespace your.app
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(Configuration);
            services.AddMvc().AddNewtonsoftJson();

            /*
             * Initializing Magic.
             * Notice, must be done AFTER you invoke "AddMvc".
             */
            services.AddMagic(Configuration, Configuration["magic:license"]);
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            /*
             * Initializing Magic.
             * Notice, must be done BEFORE you invoke "UseEndpoints".
             */
            app.UseMagic(Configuration);

            app.UseHttpsRedirection();
            app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
            app.UseAuthentication();
            app.UseRouting();
            app.UseEndpoints(conf => conf.MapControllers());
        }
    }
}

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.

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.

If you use these methods instead of the “do all methods”, probably a large portion of your motivation would be to replace one of these methods with your own implementation, to exchange the default wiring up, 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”.

Project website

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.

Quality gates

License

This project is the copyright(c) 2020-2021 of Thomas Hansen thomas@servergardens.com, and is licensed under the terms of the LGPL version 3, as published by the Free Software Foundation. See the enclosed LICENSE file for details.