Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <JwtAuthenticationService.Options>(
                Configuration.GetSection("Authentication"));

            services.Configure <ImageProcessingService.Options>(
                Configuration.GetSection("ImageProcessing"));

            JwtAuthenticationService.AddJwtAuthentication(
                services,
                Configuration.GetValue <string>("Authentication:Secret"));

            services.AddSingleton(sp =>
                                  new Database(Configuration.GetConnectionString("DefaultConnection")));

            services.AddSingleton(sp =>
                                  new AzureStorage(Configuration.GetConnectionString("StorageConnection")));

            services.AddSingleton <MigrationDataSource>();
            services.AddSingleton <UserDataSource>();
            services.AddSingleton <IdentityDataSource>();
            services.AddSingleton <PostDataSource>();
            services.AddSingleton <FollowDataSource>();

            services.AddSingleton <MigrationService>();
            services.AddSingleton <IdentityService>();
            services.AddSingleton <ImageProcessingService>();
            services.AddSingleton <JwtAuthenticationService>();

            services.AddMvc(options =>
            {
                options.Filters.Add(new ValidateModelAttribute());
                options.InputFormatters.RemoveType <JsonPatchInputFormatter>();
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Social API", Version = "v1"
                });
                c.IncludeXmlComments(Path.Combine(
                                         AppContext.BaseDirectory,
                                         Assembly.GetEntryAssembly().GetName().Name + ".xml"));

                c.OperationFilter <JsonOperationFilter>();
                c.OperationFilter <AuthResponsesOperationFilter>();
                c.OperationFilter <FormFileOperationFilter>();
                c.OperationFilter <ResponseCodeOperationFilter>();
            });

            services.AddCors();
        }
Пример #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <JwtAuthenticationService.Options>(
                Configuration.GetSection("Authentication"));

            JwtAuthenticationService.AddJwtAuthentication(
                services,
                Configuration.GetValue <string>("Authentication:Secret"));

            services.AddMongo(Configuration.GetSection("Mongo"));

            services.AddRedis(Configuration.GetSection("Redis"));

            services.AddSingleton <IdentityService>();
            services.AddSingleton <JwtAuthenticationService>();
            services.AddCors();

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

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "Messenger API", Version = "v1"
                });

                // TODO: не исопльзовать имена сборок явно
                c.IncludeXmlComments(Path.Combine(
                                         AppContext.BaseDirectory, "WebApi.xml"));
                c.IncludeXmlComments(Path.Combine(
                                         AppContext.BaseDirectory, "Abstractions.xml"));

                c.OperationFilter <JsonOperationFilter>();
                c.OperationFilter <AuthResponsesOperationFilter>();
                c.OperationFilter <ResponseCodeOperationFilter>();
            });

            // services.AddCors();
        }