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)
        {
            services.AddControllers();

            // Identity
            services.AddDbContext <SecurityContext>(options =>
                                                    options.UseNpgsql(Configuration.GetConnectionString("Default"),
                                                                      x => x.MigrationsHistoryTable("__MigrationsHistory", SecurityContext.DEFAULT_SCHEMA)));

            IdentityHelper.ConfigureService(services);

            // Helpers
            AuthenticationHelper.ConfigureService(services, Configuration["JwtSecurityToken:Issuer"], Configuration["JwtSecurityToken:Audience"], Configuration["JwtSecurityToken:Key"]);
            CorsHelper.ConfigureService(services);
            SwaggerHelper.ConfigureService(services);

            // Settings
            services.Configure <EmailSettings>(Configuration.GetSection("Email"));
            services.Configure <ClientAppSettings>(Configuration.GetSection("ClientApp"));
            services.Configure <JwtSecurityTokenSettings>(Configuration.GetSection("JwtSecurityToken"));
            services.Configure <QRCodeSettings>(Configuration.GetSection("QRCode"));

            // Services
            services.AddTransient <IEmailService, EmailService>();

            // Azure
            // Azure Storage Services
            services.AddScoped <IBlobStorage>(s => new BlobStorage(Configuration["ConnectionStrings:AzureStorage"], Configuration["AzureStorage:ContainerName"], Configuration["AzureStorage:Url"]));
            services.AddScoped <IQueueStorage>(s => new QueueStorage(Configuration["ConnectionStrings:AzureStorage"]));

            // Data
        }
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)
        {
            //https://github.com/shammelburg/CoreIdentity
            // Identity
            services.AddDbContext <Api.Identity.SecurityContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:DefaultConnection"]));
            // Tools->NuGet Package Manager -> Package Manager Console
            // Initialise
            // add-migration init -Context SecurityContext
            // update or create DB
            // update-database -Context SecurityContext
            IdentityHelper.ConfigureService(services);

            // Helpers
            AuthenticationHelper.ConfigureService(services, Configuration["JwtSecurityToken:Issuer"], Configuration["JwtSecurityToken:Audience"], Configuration["JwtSecurityToken:Key"]);
            CorsHelper.ConfigureService(services);
            SwaggerHelper.ConfigureService(services);

            // Settings
            services.Configure <EmailSettings>(Configuration.GetSection("Email"));
            services.Configure <ClientAppSettings>(Configuration.GetSection("ClientApp"));
            services.Configure <JwtSecurityTokenSettings>(Configuration.GetSection("JwtSecurityToken"));
            //services.Configure<QRCodeSettings>(Configuration.GetSection("QRCode"));

            // Services
            services.AddTransient <IEmailService, EmailService>();
            services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>));
            services.AddTransient <IUnitOfWork, UnitOfWork>();

            services.AddControllers();
            services.AddHttpContextAccessor();

            // Mapper
            services.AddAutoMapper(typeof(AutoMapping));

            //Define upload
            services.Configure <FormOptions>(o => {
                o.ValueLengthLimit         = int.MaxValue;
                o.MultipartBodyLengthLimit = int.MaxValue;
                o.MemoryBufferThreshold    = int.MaxValue;
            });
        }
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)
        {
            // Identity
            services.AddDbContext <SecurityContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:Default"]));

            // Tools->NuGet Package Manager -> Package Manager Console
            // Initialise
            // add-migration init -Context SecurityContext
            // update or create DB
            // update-database -Context SecurityContext
            IdentityHelper.ConfigureService(services);

            // Helpers
            AuthenticationHelper.ConfigureService(services, Configuration["JwtSecurityToken:Issuer"], Configuration["JwtSecurityToken:Audience"], Configuration["JwtSecurityToken:Key"]);
            CorsHelper.ConfigureService(services);
            SwaggerHelper.ConfigureService(services);

            // Settings
            services.Configure <EmailSettings>(Configuration.GetSection("Email"));
            services.Configure <ClientAppSettings>(Configuration.GetSection("ClientApp"));
            services.Configure <JwtSecurityTokenSettings>(Configuration.GetSection("JwtSecurityToken"));
            services.Configure <QRCodeSettings>(Configuration.GetSection("QRCode"));

            // Services
            services.AddTransient <IEmailService, EmailService>();

            // Azure
            // Azure Storage Services
            services.AddScoped <IBlobStorage>(s => new BlobStorage(Configuration["ConnectionStrings:AzureStorage"], Configuration["AzureStorage:ContainerName"], Configuration["AzureStorage:Url"]));
            services.AddScoped <IQueueStorage>(s => new QueueStorage(Configuration["ConnectionStrings:AzureStorage"]));

            // Data
            services.AddDbContextPool <DataContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:Default"]));
            services.AddScoped <IExampleRepo, ExampleRepo>();

            services.AddControllers();
        }
Exemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Auto Mapper Configurations
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new MappingProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            // Identity
            services.AddDbContext <SchoolDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

            // Identity kurulumu için
            // Tools->NuGet Package Manager -> Package Manager Console
            // add-migration init -Context SecurityContext
            // update-database -Context SecurityContext
            IdentityHelper.ConfigureService(services);

            // Helpers
            AuthenticationHelper.ConfigureService(services, Configuration["JwtSecurityToken:Issuer"], Configuration["JwtSecurityToken:Audience"], Configuration["JwtSecurityToken:Key"]);
            CorsHelper.ConfigureService(services);

            // Settings
            services.Configure <JwtSecurityTokenSettings>(Configuration.GetSection("JwtSecurityToken"));

            // Services
            //services.AddTransient<IEmailService, EmailService>();

            //Data
            services.AddDbContext <SchoolDbContext>(options =>
                                                    options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "School API",
                    Version = "v1"
                });
                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In          = ParameterLocation.Header,
                    Description = "Please insert JWT with Bearer into field",
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            }
                        },
                        new string[] { }
                    }
                });
            });

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