Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            JwtSettings jwtSettings = new JwtSettings();

            Configuration.Bind(nameof(JwtSettings), jwtSettings);
            services.AddSingleton(jwtSettings);

            WnsSettings wnsSettings = new WnsSettings();

            Configuration.Bind(nameof(WnsSettings), wnsSettings);
            services.AddSingleton(wnsSettings);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = jwtSettings.Issuer,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings.Key))
                };
            });

            services.AddDbContext <NotificationsDbContext>(options =>
            {
                options.UseSqlite(Configuration.GetConnectionString("SQLiteConnection"));
                //options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            });


            services.AddScoped <AccountService>();
            services.AddScoped <NotificationsService>();
            services.AddScoped <IEncrypter, Encrypter>();
            services.AddScoped <NewsService>();
            services.AddScoped <JwtService>();

            services.AddScoped <IPushNotificationSender, WindowsPushNotificationService>();
            services.AddScoped <WNSAuthenticationHelper>();
            services.AddScoped <WnsTokenStorage>();

            services.AddScoped <ICommandDispatcher, CommandDispatcher>();

            services.AddScoped <ICommandHandler <Register>, RegisterHandler>();
            services.AddScoped <ICommandHandler <CreateToken>, CreateTokenHandler>();
            services.AddScoped <ICommandHandler <UpdatePreferences>, UpdatePreferencesHandler>();
            services.AddScoped <ICommandHandler <UpdatePushChannel>, UpdatePushChannelHandler>();
            services.AddScoped <ICommandHandler <ShowAccountList>, ShowAccountListHandler>();

            services.AddHostedService <TimedHostedService>();
        }
Exemple #2
0
 public WNSAuthenticationHelper(WnsSettings wnsSettings, WnsTokenStorage wnsTokenStorage)
 {
     sid    = wnsSettings.Sid;
     secret = wnsSettings.Secret;
     this.wnsTokenStorage = wnsTokenStorage;
 }
Exemple #3
0
 public WindowsPushNotificationService(WnsSettings wnsSettings, WNSAuthenticationHelper wnsAuthentication)
 {
     this.wnsSettings       = wnsSettings;
     this.wnsAuthentication = wnsAuthentication;
 }