Exemple #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 http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Entity Framework services to the services container.
            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <PhotoGalleryContext>(options =>
                                                options.UseSqlServer(Configuration["Data:PhotoGalleryConnection:ConnectionString"]));

            // Repositories
            services.AddScoped <IPhotoRepository, PhotoRepository>();
            services.AddScoped <IAlbumRepository, AlbumRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserRoleRepository, UserRoleRepository>();
            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <ILoggingRepository, LoggingRepository>();

            // Services
            services.AddScoped <IMembershipService, MembershipService>();
            services.AddScoped <IEncryptionService, EncryptionService>();

            services.AddAuthentication();

            // Polices
            services.AddAuthorization(options =>
            {
                // inline policies
                options.AddPolicy("AdminOnly", policy =>
                {
                    policy.RequireClaim(ClaimTypes.Role, "Admin");
                });
            });

            // Add MVC services to the services container.
            services.AddMvc();
        }
 // 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 #3
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.AddMvc();

            // به کنترلرها تزریق کنیم، به این دستور نیاز داریم DatabaseContext در صورتی که بخواهیم
            services.AddDbContext <Models.DatabaseContext>(options =>
                                                           options.UseSqlServer(Configuration.GetConnectionString(name: "DatabaseContext")));
        }
        // 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.AddMvc((options) =>
            {
            })

            .AddApplicationPart(typeof(SimulatorController).GetTypeInfo().Assembly);
        }
        // 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.AddAuthentication("Bearer")
            .DSAddJwtBearer(options =>
            {
                options.AudienceAuthorityResolver = new CognitoUserPoolResolver(new DataContext());
            });

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

            services.AddScoped <IIAASService, AWSCognitoService>();
            services.AddScoped <DataContext>();
        }
        // 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.AddAuthentication();

            services.AddSignalR();
            // Add framework services.
            //services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
            // Add MVC services to the services container.
            services.AddMvc()
            .AddJsonOptions(opts =>
            {
                opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
        }
Exemple #7
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 <ForwardedHeadersOptions>(options =>
            {
                // TODO: Add configurable proxy list
                // options.KnownProxies.Add(IPAddress.Parse("10.0.0.100"));
            });

            services.AddSingleton(new SqlService());


            services.AddMvc();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.AddAspNetCoreSystemServices();
            services.AddMvc()
            .AddJsonOptions(
                s => SF.Core.Serialization.Newtonsoft.JsonSerializer.ApplySetting(
                    s.SerializerSettings,
                    new SF.Core.Serialization.JsonSetting
            {
                IgnoreDefaultValue = true,
                WithType           = false
            })
                );

            var ins = HygouApp.Setup(SF.Core.Hosting.EnvironmentType.Production, services)
                      .With(sc =>
                            sc.AddAspNetCoreSupport()
                            .AddAccessTokenHandler(
                                "HYGOU",
                                "123456",
                                null,
                                null
                                )
                            )
                      .OnEnvType(
                t => t != EnvironmentType.Utils,
                sc =>
            {
                sc.AddNetworkService();
                sc.AddAspNetCoreServiceInterface();
                sc.AddIdentityServer4Support();
                var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("system"));
                sc.AddSingleton <ISigningCredentialStore>(
                    new DefaultSigningCredentialsStore(
                        new Microsoft.IdentityModel.Tokens.SigningCredentials(
                            key,
                            SecurityAlgorithms.HmacSha256
                            )
                        ));
            }
                )
                      .Build();

            return(ins.ServiceProvider);
        }
Exemple #9
0
        public void ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
        {
            services.Configure <SessionOptions>(option => option.IdleTimeout = TimeSpan.FromMinutes(30));
            services.AddCaching();
            services.AddSession();

            services.AddMvc();

            services.Configure <MvcOptions>(Router.Instance.Route);

            services.Configure <MvcOptions>(options =>
            {
                //options.Filters.Add(typeof(ActionFilter));
                //options.Filters.Add(typeof(ResultFilter));
                //options.Filters.Add(typeof(AuthorizationFilter));
                options.Filters.Add(typeof(ExceptionFilter));
            });

            services.AddEntityFramework().AddSqlServer().AddDbContext <ApplicationDbContext>();
        }
Exemple #10
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.AddOptions();
            services.AddMvc();
            services.AddCors();
            services.AddOptions();

            services.AddSingleton <IDictaatRepository, DictaatRepository>();
            services.AddSingleton <IPageRepository, PageRepository>();
            services.AddSingleton <IMenuRepository, MenuRepository>();
            services.AddScoped <IQuestionRepository, QuestionRepository>();

            services.AddSingleton <Core.IDirectory, Core.Directory>();
            services.AddSingleton <Core.IFile, Core.File>();
            services.Configure <ConfigVariables>(Configuration.GetSection("ConfigVariables"));

            var connection = @"Server = Stijn; Database = Webdictaat; Trusted_Connection = True; MultipleActiveResultSets=True";

            services.AddDbContext <DomainContext>(options => options.UseSqlServer(connection), ServiceLifetime.Scoped);
        }
Exemple #11
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)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();

            services.Configure <RazorViewEngineOptions>(razor => razor.ViewLocationExpanders.Add(new ViewLocationExpander()));

            services.AddSwaggerGen();
            services.ConfigureSwaggerDocument(options =>
            {
                options.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "smtp4dev",
                    Description    = "SMTP server for development",
                    TermsOfService = "None"
                });
            });

            services.UseSmtp4dev();
        }
Exemple #12
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();
        }
Exemple #13
0
 public override void Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection services)
 {
     services.AddMvc();
 }
Exemple #14
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)
        {
            // **************************************************
            // Add framework services.
            //services.AddMvc(); // Default

            //services.AddMvc(options =>
            //	options.Filters.Add(new Infrastructure.Attributes.Filters.SecurityActionFilterAttribute())
            //);

            services.AddMvc(options =>
            {
                options.Filters.Add
                    (typeof(Infrastructure.Filters.SecurityActionFilterAttribute));
            });
            // **************************************************

            // **************************************************
            // https://docs.microsoft.com/en-us/aspnet/core/security/cors

            // دستور ذیل ظاهرا کار نمی‌کند
            //services.Configure<Microsoft.AspNetCore.Mvc.MvcOptions>(options =>
            //{
            //	options.Filters.Add
            //		(new Microsoft.AspNetCore.Mvc.Cors.Internal.CorsAuthorizationFilterFactory("AllowSpecificOrigin"));
            //});

            //services.AddCors(options =>
            //{
            //	options.AddPolicy(name: "AllowSpecificOrigin",
            //		configurePolicy: builder => builder.WithOrigins("http://localhost:3000", "http://www.IranainExperts.ir"));
            //});

            //services.AddCors(options =>
            //{
            //	options.AddPolicy(name: "AllowSpecificOrigin",
            //		configurePolicy: builder => builder.AllowAnyOrigin());
            //});

            //services.AddCors(options =>
            //{
            //	options.AddPolicy(name: "AllowSpecificOrigin",
            //		configurePolicy: builder =>
            //		builder
            //		.WithOrigins("http://localhost:3000")
            //		.AllowAnyMethod());
            //});

            //services.AddCors(options =>
            //{
            //	options.AddPolicy(name: "AllowSpecificOrigin",
            //		configurePolicy: builder =>
            //		builder
            //		.WithOrigins("http://localhost:3000")
            //		.WithHeaders("accept", "content-type", "origin", "x-custom-header"));
            //});

            //services.AddCors(options =>
            //{
            //	options.AddPolicy(name: "AllowSpecificOrigin",
            //		configurePolicy: builder =>
            //		builder
            //		.WithOrigins("http://localhost:3000")
            //		.AllowAnyHeader());
            //});

            services.AddCors(options =>
            {
                options.AddPolicy(name: "AllowSpecificOrigin",
                                  configurePolicy: builder =>
                                  builder
                                  .AllowAnyHeader()
                                  .AllowAnyMethod()
                                  .AllowAnyOrigin()
                                  .AllowCredentials()
                                  );
            });
            // **************************************************
        }