예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn = Configuration.GetConnectionString("conn");

            services.AddDbContext <MyDBContext>(
                op => op.UseSqlServer(conn));

            var authconn = Configuration.GetConnectionString("authconn");

            services.AddDbContext <ApplicationAuthContext>(
                op => op.UseSqlServer(authconn));

            services.AddIdentity <security.User, security.Role>()
            .AddEntityFrameworkStores <ApplicationAuthContext>()
            .AddDefaultTokenProviders();

            ApplicationSetup.RegisterServices(services);


            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            services.AddLogging();



            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Flight_Booking", Version = "v1"
                });
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            var conn = Configuration.GetConnectionString("conn");

            services.AddDbContext <MyDatabaseContext>(
                op => op.UseSqlServer(conn));

            var authconn = Configuration.GetConnectionString("conn");

            services.AddDbContext <ApplicationAuthContext>(
                op => op.UseSqlServer(authconn));

            //For  Identity
            services.AddIdentity <ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationAuthContext>()
            .AddDefaultTokenProviders();

            //Adding Authentication
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })

            //Adding Jwt Bearer
            .AddJwtBearer(options =>
            {
                options.SaveToken                 = true;
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer   = true,
                    ValidateAudience = true,
                    //ValidateLifetime = true,
                    //ValidateIssuerSigningKey = true,
                    ValidAudience    = Configuration["Jwt:ValidAudience"],
                    ValidIssuer      = Configuration["Jwt:ValidIssuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
                };
            });

            ApplicationSetup.RegisterServices(services);

            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "FlightBooking", Version = "v1"
                });
            });
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var conn = Configuration.GetConnectionString("conn");

            services.AddDbContext <BookingDatabaseContext>(
                op => op.UseSqlServer(conn));

            ApplicationSetup.RegisterServices(services);

            services.AddControllers()
            .AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "FlightBooking", Version = "v1"
                });
            });
        }