Exemplo n.º 1
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();
        }
Exemplo n.º 2
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";
            });
        }
Exemplo n.º 3
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     ServicesStartup.ConfigureServices(services, Configuration);
     services.AddControllersWithViews();
 }