Пример #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().AddNewtonsoftJson(optitons => optitons.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer = true,
                    ValidIssuer    = JwtOptions.ISSUER,

                    ValidateAudience = true,
                    ValidAudience    = JwtOptions.AUDIENCE,

                    ValidateLifetime = true,


                    IssuerSigningKey         = JwtOptions.GetSymmetricSecurityKey(),
                    ValidateIssuerSigningKey = true
                };
            });

            ServiceCreator serviceCreator = new ServiceCreator(Configuration.GetConnectionString("DefaultConnection"));

            services.AddScoped <ICommentService, CommentService>(conf => serviceCreator.CreateCommentService());
            services.AddScoped <IPostService, PostService>(conf => serviceCreator.CreatePostService());
            services.AddScoped <IUserProfileService, UserProfileService>(conf => serviceCreator.CreateUserProfileService());
            services.AddScoped <IApplicationUserService, ApplicationUserService>(conf => serviceCreator.CreateApplicationUserService());
        }
Пример #2
0
 public PostController()
 {
     _postService = _service.CreatePostService();
     GetUserId    = () => User.Identity.GetUserId();
 }