public void ConfigureServices(IServiceCollection services) { services.AddLogging(options => options.AddConsole()); services.AddCors(); if (_hostEnv.IsProduction()) { var connectionString = ConnectionStringHelper.GetConnectionString(Configuration); services.AddDbContext <AuthContext>(options => options.UseMySql(connectionString)); services.AddDbContext <ChatContext>(options => options.UseMySql(connectionString)); } else { services.AddDbContext <AuthContext>(options => options.UseInMemoryDatabase(nameof(AuthContext))); services.AddDbContext <ChatContext>(options => options.UseInMemoryDatabase(nameof(ChatContext))); } services.AddIdentity <IdentityUser, IdentityRole>( config => { config.Password.RequireNonAlphanumeric = false; }) .AddEntityFrameworkStores <AuthContext>() .AddDefaultTokenProviders(); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); var jwtConfiguration = new JwtConfiguration(Configuration); services.AddSingleton(jwtConfiguration); services.AddAuthentication() .AddJwtBearer( JwtSchemes.Admin, options => jwtConfiguration.ConfigureJwtBearerOptions(JwtSchemes.Admin, options)) .AddJwtBearer( JwtSchemes.User, options => jwtConfiguration.ConfigureJwtBearerOptions(JwtSchemes.User, options)); services.AddTransient <IUnitOfWork, UnitOfWork>(); services.AddTransient <IUsersManager, UsersManager>(); services.AddTransient <IChatroomsManager, ChatroomsManager>(); services.AddTransient <IMessagesManager, MessagesManager>(); services.AddSingleton <INotificationsService, NotificationsService>(); services.AddSingleton <IMessageParser, MessageParser>(); services.AddControllers(); }