Beispiel #1
0
        // This method gets called by the runtime.. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });


            ElephantSQLCredentials creds = new ElephantSQLCredentials()
            {
                Database = Configuration.GetSection("elephantsql:0:credentials:database").Value,
                Password = Configuration.GetSection("elephantsql:0:credentials:password").Value,
                Port     = Configuration.GetSection("elephantsql:0:credentials:portnum").Value,
                Server   = Configuration.GetSection("elephantsql:0:credentials:hostname").Value,
                Username = Configuration.GetSection("elephantsql:0:credentials:username").Value
            };
            var appName = "ASP.NET Core RC2 ToDo Sample";

            var connection = string.Format(@"Server={0};Port={1};User Id={2};Password={3};Database={4};"
                                           + "SSL Mode=Require;Application Name={5}",
                                           creds.Server, creds.Port, creds.Username, creds.Password, creds.Database, appName);

            services.AddEntityFrameworkNpgsql()
            .AddDbContext <ToDoDbContext>(options => options.UseNpgsql(connection));

            // Add framework services.
            services.AddMvc();
            services.AddScoped <IMarkRepository, IMarkRepository>();
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ElephantSQLCredentials creds = new ElephantSQLCredentials()
            {
                Database = Configuration.GetSection("elephantsql:0:credentials:database").Value,
                Password = Configuration.GetSection("elephantsql:0:credentials:password").Value,
                Port     = Configuration.GetSection("elephantsql:0:credentials:portnum").Value,
                Server   = Configuration.GetSection("elephantsql:0:credentials:hostname").Value,
                Username = Configuration.GetSection("elephantsql:0:credentials:username").Value
            };
            var appName    = "ASP.NET Core RC2 ToDo Sample";
            var connection = string.Format(@"Server={0};Port={1};User Id={2};Password={3};Database={4};"
                                           + "SSL Mode=Require;Application Name={5}",
                                           creds.Server, creds.Port, creds.Username, creds.Password, creds.Database, appName);

            services.AddEntityFrameworkNpgsql()
            .AddDbContext <Context>(options => options.UseNpgsql(connection));

            // Add framework services.
            // Here we create a new cors policy that should work on the entire application
            services.AddCors(option => {
                option.AddPolicy("CorsPolicy",
                                 ////builder => builder.WithOrigins("https://corsclient.mybluemix.net"));
                                 builder => builder
                                 .AllowAnyOrigin()
                                 .AllowAnyMethod()
                                 .AllowAnyHeader()
                                 );
            });

            // Here we configure the MVC Options
            services.AddMvc().AddJsonOptions(options => {
                options.SerializerSettings.ContractResolver      = new CamelCasePropertyNamesContractResolver();
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            });

            // Register Application services
            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <IVoucherRepository, VoucherRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IOrderRepository, OrderRepository>();
            services.AddScoped <IShowroomerRepository, ShowroomerRepository>();
            services.AddScoped <IShowroomRepository, ShowroomRepository>();
            services.AddScoped <IBuyerRepository, BuyerRepository>();
            services.AddScoped <IInteractionRepository, InteractionRepository>();
            services.AddScoped <IImageRepository, ImageRepository>();
            services.AddScoped <IRateRepository, RateRepository>();
            services.AddScoped <ICommentRepository, CommentRepository>();
            services.AddScoped <IPurchaseRepository, PurchaseRepository>();
            services.AddScoped <IShowroomerReviewRepository, ShowroomerReviewRepository>();
        }