Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration["SqlConnection:UserDB"];

            services.AddDbContext <UserDbContext>(options =>
                                                  options.UseSqlServer(connectionString));
            services.AddDatabaseDeveloperPageExceptionFilter();

            services.AddDefaultIdentity <ApplicationUser>(options =>
            {
                options.SignIn.RequireConfirmedEmail    = true;
                options.SignIn.RequireConfirmedAccount  = true;
                options.Password.RequiredLength         = 8;
                options.Password.RequireNonAlphanumeric = false;
                options.Lockout.MaxFailedAccessAttempts = 5;
            })
            .AddRoles <IdentityRole>()
            .AddEntityFrameworkStores <UserDbContext>();

            services.Configure <SecurityStampValidatorOptions>(options =>
            {
                //validate logged in user every 5 min
                options.ValidationInterval = TimeSpan.FromMinutes(5);
            });

            var orderApiOptions   = new OrderApiTokenOptions();
            var productApiOptions = new ProductApiTokenOptions();

            Configuration.Bind("ApiTokenOptions:Order", orderApiOptions);
            Configuration.Bind("ApiTokenOptions:Product", productApiOptions);
            services.AddSingleton <ProductApiTokenOptions>(productApiOptions);
            services.AddSingleton <OrderApiTokenOptions>(orderApiOptions);

            services.AddSingleton <ITokenService, TokenService>();

            services.AddSingleton <IProductService, ProductService>();
            services.AddHttpClient <IProductRepository, ProductRepository>(client =>
                                                                           client.BaseAddress = new Uri(Configuration["ProductAPIUrl"])
                                                                           );
            services.AddSingleton <IOrderService, OrderService>();
            services.AddHttpClient <IOrderRepository, OrderRepository>(client =>
                                                                       client.BaseAddress = new Uri(Configuration["OrderAPIUrl"])
                                                                       );
            services.AddHttpContextAccessor();
            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout        = TimeSpan.FromMinutes(20);
                options.Cookie.HttpOnly    = true;
                options.Cookie.IsEssential = true;
            });
            services.AddTransient <ICartRepository, CartRepository>();
            services.AddTransient <ICartService, CartService>();
            services.AddTransient <IInventoryService, InventoryService>();

            services.AddServerSideBlazor();
            services.AddControllersWithViews();
        }
Exemple #2
0
 public TokenService(ProductApiTokenOptions productApiOptions, OrderApiTokenOptions orderApiOptions)
 {
     _productApiOptions = productApiOptions;
     _orderApiOptions   = orderApiOptions;
 }