예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var path = Path.Combine(_path, _jsonFileName);

            services.AddSingleton <IDataStore>(new DataStore(path, reloadBeforeGetCollection: Configuration.GetValue <bool>("Common:EagerDataReload")));
            services.AddSingleton <IMessageBus, MessageBus>();
            services.AddSingleton(typeof(JobsService));

            services.Configure <AuthenticationSettings>(Configuration.GetSection("Authentication"));
            services.Configure <ApiSettings>(Configuration.GetSection("Api"));
            services.Configure <JobsSettings>(Configuration.GetSection("Jobs"));
            services.Configure <SimulateSettings>(Configuration.GetSection("Simulate"));

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            if (Configuration.GetValue <bool>("Authentication:Enabled"))
            {
                if (Configuration.GetValue <string>("Authentication:AuthenticationType") == "token")
                {
                    TokenConfiguration.Configure(services);
                }
                else
                {
                    BasicAuthenticationConfiguration.Configure(services);
                }
            }
            else
            {
                AllowAllAuthenticationConfiguration.Configure(services);
            }

            services.AddMvc();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Fake JSON API", Version = "v1"
                });

                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "FakeServer.xml");
                c.IncludeXmlComments(xmlPath);
            });
        }
예제 #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            var folder = Configuration["staticFolder"];

            if (!string.IsNullOrEmpty(folder))
            {
                services.AddSpaStaticFiles((spa) =>
                {
                    spa.RootPath = folder;
                });

                // No need to define anything else as this can only be used as a SPA server
                return;
            }

            var jsonFilePath = Path.Combine(Configuration["currentPath"], Configuration["file"]);

            services.AddSingleton <IDataStore>(new DataStore(jsonFilePath, reloadBeforeGetCollection: Configuration.GetValue <bool>("Common:EagerDataReload")));
            services.AddSingleton <IMessageBus, MessageBus>();
            services.AddSingleton <JobsService>();

            services.Configure <AuthenticationSettings>(Configuration.GetSection("Authentication"));
            services.Configure <ApiSettings>(Configuration.GetSection("Api"));
            services.Configure <JobsSettings>(Configuration.GetSection("Jobs"));
            services.Configure <SimulateSettings>(Configuration.GetSection("Simulate"));

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            var useAuthentication = Configuration.GetValue <bool>("Authentication:Enabled");

            if (useAuthentication)
            {
                if (Configuration["Authentication:AuthenticationType"] == "token")
                {
                    var blacklistService = new TokenBlacklistService();
                    services.AddSingleton(blacklistService);

                    TokenConfiguration.Configure(services);
                }
                else
                {
                    BasicAuthenticationConfiguration.Configure(services);
                }
            }
            else
            {
                AllowAllAuthenticationConfiguration.Configure(services);
            }

            services.AddMvc();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Fake JSON API", Version = "v1"
                });

                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "FakeServer.xml");
                c.IncludeXmlComments(xmlPath);

                if (useAuthentication)
                {
                    c.OperationFilter <AddAuthorizationHeaderParameterOperationFilter>();

                    if (Configuration["Authentication:AuthenticationType"] == "token")
                    {
                        c.DocumentFilter <AuthTokenOperation>();
                    }
                }
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var jsonFilePath = Path.Combine(Configuration.GetValue <string>("currentPath"), Configuration.GetValue <string>("file"));

            services.AddSingleton <IDataStore>(new DataStore(jsonFilePath, reloadBeforeGetCollection: Configuration.GetValue <bool>("Common:EagerDataReload")));
            services.AddSingleton <IMessageBus, MessageBus>();
            services.AddSingleton(typeof(JobsService));

            services.Configure <AuthenticationSettings>(Configuration.GetSection("Authentication"));
            services.Configure <ApiSettings>(Configuration.GetSection("Api"));
            services.Configure <JobsSettings>(Configuration.GetSection("Jobs"));
            services.Configure <SimulateSettings>(Configuration.GetSection("Simulate"));

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAnyPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            var useAuthentication = Configuration.GetValue <bool>("Authentication:Enabled");

            if (useAuthentication)
            {
                if (Configuration.GetValue <string>("Authentication:AuthenticationType") == "token")
                {
                    var blacklistService = new TokenBlacklistService();
                    services.AddSingleton(blacklistService);

                    TokenConfiguration.Configure(services, blacklistService);
                }
                else
                {
                    BasicAuthenticationConfiguration.Configure(services);
                }
            }
            else
            {
                AllowAllAuthenticationConfiguration.Configure(services);
            }

            services.AddMvc();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Generic JSON SQL Api", Version = "v1"
                });

                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "FakeServer.xml");
                c.IncludeXmlComments(xmlPath);

                if (useAuthentication)
                {
                    c.OperationFilter <AddAuthorizationHeaderParameterOperationFilter>();

                    if (Configuration.GetValue <string>("Authentication:AuthenticationType") == "token")
                    {
                        c.DocumentFilter <AuthTokenOperation>();
                    }
                }
            });
        }