// method runs after Constructor is done in first run
 // parameter of type IServiceCollection is passed into this method
 // doesn't return anything
 public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services.AddDbContext <Models.ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreProducts:ConnectionString"]));
     services.AddDbContext <Models.AppIdentityDbContext>(options => options.UseSqlServer(Configuration["Data:BilliardStoreIdentity:ConnectionString"]));
     services.AddIdentity <Microsoft.AspNetCore.Identity.IdentityUser, Microsoft.AspNetCore.Identity.IdentityRole>()
     .AddEntityFrameworkStores <BilliardStore.Models.AppIdentityDbContext>()
     .AddDefaultTokenProviders();
     services.AddTransient <Models.IProductRepository, Models.EFProductRepository>();
     services.AddScoped <Models.Cart>(sp => Models.SessionCart.GetCart(sp));
     services.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>();
     services.AddTransient <Models.IOrderRepository, Models.EFOrderRepository>();
     services.AddTransient <SendGrid.ISendGridClient>((s) =>
     {
         return(new SendGrid.SendGridClient(Configuration.GetValue <string>("SendGrid:Key")));
     });
     services.AddTransient <Braintree.IBraintreeGateway>((s) =>
     {
         return(new Braintree.BraintreeGateway(
                    Configuration.GetValue <string>("Braintree:Environment"),
                    Configuration.GetValue <string>("Braintree:MerchantId"),
                    Configuration.GetValue <string>("Braintree:PublicKey"),
                    Configuration.GetValue <string>("Braintree:PrivateKey")));
     });
     services.AddTransient <SmartyStreets.IClient <SmartyStreets.USStreetApi.Lookup> >((s) =>
     {
         return(new SmartyStreets.ClientBuilder(
                    Configuration.GetValue <string>("SmartyStreets:AuthId"),
                    Configuration.GetValue <string>("SmartyStreets:AuthToken")
                    ).BuildUsStreetApiClient());
     });
     services.AddMvc();
     services.AddMemoryCache();
     services.AddSession();
 }                                                                                                                                                                                                                                                                                        // makes EFProductRepository take the place of IProductRepository in the code
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.Configure <FormOptions>(o => {
                o.ValueLengthLimit         = int.MaxValue;
                o.MultipartBodyLengthLimit = int.MaxValue;
                o.MemoryBufferThreshold    = int.MaxValue;
            });


            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("MSSQL")));

            services.AddIdentity <ApplicationUser, IdentityRole>(cfg =>
            {
                cfg.User.RequireUniqueEmail = true;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>();



            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddCookie()
            .AddJwtBearer(cfg =>
            {
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidIssuer      = this.Configuration["Tokens:Issuer"],
                    ValidAudience    = this.Configuration["Tokens:Audience"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(this.Configuration["Tokens:Key"]))
                };
            });


            services.Configure <IdentityOptions>(options =>
            {
                options.Password.RequiredLength         = 3;
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequiredUniqueChars    = 0;
            });

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder => builder.WithOrigins("http://www.taximiapi.com.aspbg.net/", "http://localhost:8100/")
                                  .AllowAnyHeader()
                                  .AllowAnyMethod()
                                  .AllowCredentials()
                                  .SetIsOriginAllowed((host) => true));
            });

            services.AddMvc();

            services.AddSignalR();

            services.AddControllers()
            .AddNewtonsoftJson(options =>
                               options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.RegisterRepositoryServices();

            services.RegisterCloudinary(Configuration);

            services.Configure <MailSettings>(Configuration.GetSection("MailSettings"));

            services.RegisterCustomServices();
        }