コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            _configuration = configuration;
            DependencyInjectionConfig.AddScope(services);

            JwtTokenConfig.AddAuthentication(services, configuration);

            DBContextConfig.Initialize(services, configuration);

            services.AddMvc();
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: Ashis27/Hiroshima
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.ConfigureServices(services);
            JwtTokenConfig.AddAuthentication(services, _appConfiguration);
            DBContextConfig.Initialize(services, _appConfiguration);

            services.AddAutoMapper();
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Hiroshima API", Version = "v1"
                });
            });
            services.AddCors(options =>
            {
                options.AddPolicy(_defaultCorsPolicyName,
                                  builder =>
                {
                    builder.WithOrigins(_appConfiguration["App:CorsOrigins"])
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.Configure <MvcOptions>(options =>
            {
                options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName));
            });

            // override modelstate
            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.InvalidModelStateResponseFactory = (context) =>
                {
                    var error  = context.ModelState.Values.First().Errors.First().ErrorMessage;
                    var result = new
                    {
                        Title   = "Validation errors",
                        Message = error
                    };
                    return(new BadRequestObjectResult(result));
                };
            });
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjectionConfig.AddScope(services);
            JwtTokenConfig.AddAuthentication(services, Configuration);
            DBContextConfig.Initialize(services, Configuration);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //var connection = @"Server=(localdb)\mssqllocaldb;Organigrama.AspNetCore.NewDb;Trusted_Connection=True;ConnectRetryCount=0";
            //services.AddDbContext<ApplicationContext>
            //(options => options.UseSqlServer(connection));
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration => {
                configuration.RootPath = "ClientApp/dist";
            });
        }
コード例 #4
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     DependencyInjectionConfig.AddScope(services);
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.Configure <ConfigurationManager>(Configuration.GetSection("ConfigurationManager"));
     JwtTokenConfig.AddAuthentication(services, Configuration);
     services.AddMvc()
     .AddJsonOptions(options =>
     {
         options.SerializerSettings.ContractResolver = new DefaultContractResolver();
         // This prevents the json serializer from parsing dates
         options.SerializerSettings.DateParseHandling = DateParseHandling.None;
         // This changes how the timezone is converted - RoundtripKind keeps the timezone that was provided and doesn't convert it
         options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     });
 }
コード例 #5
0
ファイル: Startup.cs プロジェクト: phucnguyencr/tracking
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            services.AddMvc(opt => opt.Filters.Add(new ErrorHandlingFilter()));
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

            JwtTokenConfig.AddAuthentication(services, Configuration);
            services.Configure <ApiBehaviorOptions>(opt =>
            {
                opt.SuppressModelStateInvalidFilter = true;
            });
            string conStr = Configuration.GetConnectionString("TrackingDatabase");

            services.AddDbContext <TrackingContext>(opt => opt.UseSqlServer(conStr));
        }