public static IServiceCollection AddCMSConfiguration(this IServiceCollection services, Action <TinyCmsOptions> options)
        {
            var settings = new TinyCmsOptions();

            options.Invoke(settings);
            return(Setup(services, settings));
        }
        private static IServiceCollection Setup(IServiceCollection services, TinyCmsOptions settings)
        {
            var nodeFactory = settings.NodeFactoryInstance;

            services
            .AddSingleton <ITokenDecoder, TokenDecoder>()
            .AddSingleton(nodeFactory)
            .AddSingleton(typeof(IStorageService), settings.StorageService)
            .AddSingleton(settings.JWTSettings)
            .AddSingleton(typeof(INodeStorage), settings.NodeStorage)
            .AddSingleton(typeof(INodeSerializer), settings.NodeSerializer)
            .AddSingleton(typeof(ITokenValidator), settings.TokenValidator)
            .AddSingleton((sp) =>
            {
                return(sp.GetService <INodeStorage>().Load());
            });



            if (settings.UseAuthentication)
            {
                services.AddAuthentication(x =>
                {
                    x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                    x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                })
                .AddJwtBearer(x =>
                {
                    x.RequireHttpsMetadata      = false;
                    x.SaveToken                 = true;
                    x.TokenValidationParameters = new TokenValidationParameters
                    {
                        ValidateIssuerSigningKey = true,
                        IssuerSigningKey         = settings.JWTSettings.GetSecurityKey(),
                        ValidateIssuer           = false,
                        ValidateAudience         = false
                    };
                });
            }
            return(services);
        }