Пример #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
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Language>(l =>
            {
                LanguageConfiguration.Configure(l);
                LanguageSeeder.Seed(l);
            });

            modelBuilder.Entity <HomePageData>(h =>
            {
                HomepageConfiguration.Configure(h);
                HomepageSeeder.Seed(h);
            });

            modelBuilder.Entity <TranslationCategory>(t =>
            {
                TranslationCategoryConfiguration.Configure(t);
                TranslationCategorySeeder.Seed(t);
            });

            modelBuilder.Entity <Token>(t =>
            {
                TokenConfiguration.Configure(t);
                TokenSeeder.Seed(t);
            });

            modelBuilder.Entity <Translation>(t =>
            {
                TranslationConfiguration.Configure(t);
                TranslationSeeder.Seed(t);
            });

            modelBuilder.Entity <ErrorCode>(e =>
            {
                ErrorCodeConfiguration.Configure(e);
                ErrorCodeSeeder.Seed(e);
            });

            modelBuilder.Entity <ErrorTranslation>(e =>
            {
                ErrorTranslationConfiguration.Configure(e);
                ErrorTranslationSeeder.Seed(e);
            });
        }
Пример #3
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>();
                    }
                }
            });
        }