Example #1
0
 public AccountController(AccountManager accountManager, IJwtIssuer jwtIssuer, SmsManager smsManager, TotpManager totpManager)
 {
     _accountManager = accountManager ?? throw new ArgumentNullException(nameof(accountManager));
     _jwtIssuer      = jwtIssuer ?? throw new ArgumentNullException(nameof(jwtIssuer));
     _smsManager     = smsManager;
     _totpManager    = totpManager;
 }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ExceptionFilter));
                options.Filters.Add(typeof(ModelValidationFilter));
            });

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

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

            IAccountRepository accountRepository = new InMemoryAccountRepository(new List <Account>());
            var accountManager = new AccountManager(accountRepository);

            var totpManager = new TotpManager(new TotpGenerator(),
                                              Configuration["TotpSettings:totpSecretKey"],
                                              Configuration.GetValue <int>("TotpSettings:totpTokenLifetimeInSeconds"),
                                              new InMemoryTotpTokenRepository(new Dictionary <string, int>()));

            var smsManager  = new SmsManager();
            var text        = File.ReadAllText("places.json");
            var places      = JsonConvert.DeserializeObject <List <Place> >(text);
            var tripManager = new TripManager(new AirTicketManager(new AirTicketsApi(
                                                                       Configuration["AirApiSettings:token"],
                                                                       Configuration["AirApiSettings:url"])),
                                              new InMemoryPlaceRepository(places),
                                              new InMemoryTripRepository(new List <Trip>()));

            services.AddSingleton(ConfigureSecurity(services));
            services.AddSingleton(tripManager);
            services.AddSingleton(accountManager);
            services.AddSingleton(totpManager);
            services.AddSingleton(smsManager);
        }