Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ProjectContext>(
                opt => opt.UseSqlServer(@"Server=DESKTOP-7C55TUR;Database=ProjectDB;Trusted_Connection=True;"));
            IdentityStartup.ConfigureServices(services, HostingEnvironment, Configuration);
            services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
            services.AddMvc()
            .AddJsonOptions(o => o.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore)
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            #region Services injections
            services.AddSingleton <IConfiguration>(o => Configuration);
            services.AddScoped <ProjectContext>();
            services.AddScoped <LikeService>();
            services.AddScoped <PostService>();
            services.AddScoped <CommentService>();

            services.AddScoped <IAppContext, ProjectAppContext>();

            AutoMapperConfig.RegisterMappings(services.BuildServiceProvider());
            #endregion Services injections
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string envName = this.CurrentEnvironment.EnvironmentName;

            Console.WriteLine("Environment is " + envName + ".");
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            Console.WriteLine("ASP.Net Core Environment Variable is is " + env + ".");

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddSingleton <IConfiguration>(this.Configuration);

            services.Configure <EmailSenderOptions>(this.Configuration.GetSection("EmailSender"));
            //services.AddAntiforgery(opts => opts.HeaderName = "X-XSRF-Token");
            services.AddAntiforgery(opts =>
            {
                //opts.Cookie.Name = "XSRF-TOKEN";
                opts.HeaderName = "X-XSRF-TOKEN";
            }
                                    );

            servicesStartup.ConfigureServices(services);
            identityStartup.ConfigureServices(services);
            dataStartup.ConfigureServices(this.Configuration, services);
            apiStartup.ConfigureServices(services);

            // services.AddMvc(opts =>
            // {
            //     opts.Filters.AddService(typeof(AngularAntiforgeryCookieResultFilter));
            // })
            services.AddMvc(
                options => options.EnableEndpointRouting = false
                )
            .AddFluentValidation(fv => {
                fv.RegisterValidatorsFromAssemblyContaining <IdentityStartup>();
                fv.RegisterValidatorsFromAssemblyContaining <Startup>();
            })
            //.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore)
            .AddApplicationPart(typeof(ApiStartup).Assembly)
            .AddApplicationPart(typeof(IdentityStartup).Assembly);
            // services.AddTransient<AngularAntiforgeryCookieResultFilter>();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            services.AddRouteAnalyzer();
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            // Add framework services.
            string appDbContextConnectionString = Configuration.GetConnectionString("AppDbContext");

            if ((!String.IsNullOrEmpty(appDbContextConnectionString)) &&
                (!this.developmentEnvironment))
            {
                services.AddDbContext <AppDbContext>(options =>
                                                     options.UseSqlServer(appDbContextConnectionString,
                                                                          optionsBuilder => optionsBuilder.MigrationsAssembly("Banico.Data")));
            }
            else
            {
                var connectionStringBuilder = new Microsoft.Data.Sqlite.SqliteConnectionStringBuilder {
                    DataSource = "banico.db"
                };
                appDbContextConnectionString = connectionStringBuilder.ToString();
                services.AddDbContext <AppDbContext>(options =>
                                                     options.UseSqlite(appDbContextConnectionString,
                                                                       optionsBuilder => optionsBuilder.MigrationsAssembly("Banico.Data")));
            }

            services.Configure <AuthMessageSenderOptions>(Configuration);
            //services.AddAntiforgery(opts => opts.HeaderName = "X-XSRF-Token");
            services.AddAntiforgery(opts =>
            {
                //opts.Cookie.Name = "XSRF-TOKEN";
                opts.HeaderName = "X-XSRF-TOKEN";
            }
                                    );

            services.AddSingleton <IConfiguration>(Configuration);

            identityStartup.ConfigureServices(services);
            dataStartup.ConfigureServices(services);
            apiStartup.ConfigureServices(services);
            servicesStartup.ConfigureServices(services);

            // services.AddMvc(opts =>
            // {
            //     opts.Filters.AddService(typeof(AngularAntiforgeryCookieResultFilter));
            // })
            services.AddMvc()
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>())
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(
                options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                );
            // services.AddTransient<AngularAntiforgeryCookieResultFilter>();

            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }