コード例 #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var persistenceOptions = new PersistenceOptions();

            _configuration.GetSection(PersistenceOptions.Section).Bind(persistenceOptions);
            var externalOptions = new ExternalLoginProviderOptions();

            _configuration.GetSection(ExternalLoginProviderOptions.Section).Bind(externalOptions);
            services
            .AddControllersWithViews()
            .Services
            .AddHttpContextAccessor()
            .AddScoped <ICartService, CookiesCartService>()
            .AddAutoMapperWithMyProfiles("WebStore.EcommerceApp", "WebStore.Application")
            .AddCookieIdentity()
            .AddExternalProviders(externalOptions)
            .AddScoped <ISieveProcessor, CustomSieveProcessor>()
            .AddScoped <ISieveCustomFilterMethods, MyCustomSieveMethods>()
            .RegisterPersistence(persistenceOptions, _environmen)
            .AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehaviour <,>))
            .AddFluentValidation(options =>
            {
                options.RegisterValidatorsFromAssemblyContaining(typeof(FeaturedResponse <>),
                                                                 lifetime: ServiceLifetime.Scoped);
                options.AutomaticValidationEnabled          = false;
                options.LocalizationEnabled                 = false;
                options.ImplicitlyValidateChildProperties   = true;
                options.DisableDataAnnotationsValidation    = true;
                ValidatorOptions.Global.DisplayNameResolver = (type, member, expression) => member?.Name;
            })
            .AddMediatR(options => options.AsScoped(), Assembly.Load("WebStore.Application"));
        }
        public static IServiceCollection AddExternalProviders(this IServiceCollection services,
                                                              ExternalLoginProviderOptions providerOptions)
        {
            services.AddAuthentication()
            .AddGitHub(options =>
            {
                options.ClientId     = providerOptions.Github.Id;
                options.ClientSecret = providerOptions.Github.Key;
            });

            return(services);
        }