public SignInController(IServiceProvider serviceProvider, ILogger <SignInController> logger, ApplicationUserManager userManager, ApplicationSignInManager signInManager)//, SigningCredentials signingCredentials) { this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); this._signInManager = signInManager ?? throw new ArgumentNullException(nameof(signInManager)); this._serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); _signingCredentials = serviceProvider.GetService(typeof(SigningCredentials)) as SigningCredentials; _disconfService = serviceProvider.GetService(typeof(DisconfService)) as DisconfService; }
public LocalStorageProvider(DisconfService disconfService) { _disconfService = disconfService ?? throw new ArgumentNullException(nameof(disconfService)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(options => options.Filters.Add(typeof(OpenApiAuthFilter))) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(setupAction => { setupAction.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); setupAction.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; }); string connectionString = Configuration.GetConnectionString( "DefaultConnectionString"); bool isDebugMode = Configuration.GetValue <bool>("IsDebugMode"); //var signKey = new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes( // Configuration.GetValue<string>("SigningCredentials:Key"))); //SigningCredentials signingCredentials = new SigningCredentials(signKey, // SecurityAlgorithms.HmacSha256Signature); //services.AddSingleton<SigningCredentials>(signingCredentials); //string issuer = Configuration.GetValue<string>("SigningCredentials:Issuer"); //string audience = Configuration.GetValue<string>("SigningCredentials:Audience"); services.AddSingleton <IOpenAppAuthService>(impl => { return(new InternalOpenAuthService("yltbook", "85959r9wz9r7rni9izo")); }); //EntityFramework Core UseMySQL //services.AddDbContext<AppDbContext>(options => options.UseMySql(connectionString)); //Identity Framework Add JwtOptions //services.AddIdentity<ApplicationUser, ApplicationRole>(options => //{ // options.Password.RequireDigit = false; // options.Password.RequiredLength = 6; // options.Password.RequireLowercase = false; // options.Password.RequireUppercase = false; // options.Password.RequireNonAlphanumeric = false; // options.User.AllowedUserNameCharacters = string.Empty; // options.Lockout.MaxFailedAccessAttempts = 5; //}).AddDefaultTokenProviders(); //services.AddAuthentication().AddJwtBearer( // options => // { // options.TokenValidationParameters = // new TokenValidationParameters() // { // ValidateIssuer = true, // ValidateAudience = true, // ValidateLifetime = true, // ValidateIssuerSigningKey = true, // ValidIssuer = issuer, // ValidAudience = audience, // IssuerSigningKey = signKey, // }; // }); services.AddTransient <AzureStorageProvider>(); services.AddTransient <AliyunStorageProvider>(); services.AddTransient <LocalStorageProvider>(); DisconfService disconf = new DisconfService(this.Configuration); disconf.CustomConfigs.Add(AzureStorageProvider.STORAGE_PROVIDER_TYPE_KEY, AzureStorageProvider.STORAGE_PROVIDER_TYPE_VALUE); disconf.CustomConfigs.Add(AliyunStorageProvider.STORAGE_PROVIDER_TYPE_KEY, AliyunStorageProvider.STORAGE_PROVIDER_TYPE_VALUE); disconf.CustomConfigs.Add(LocalStorageProvider.STORAGE_PROVIDER_TYPE_KEY, LocalStorageProvider.STORAGE_PROVIDER_TYPE_VALUE); disconf.CustomConfigs.Add("IsDebugMode", isDebugMode); services.AddSingleton(disconf); services.AddDbContext <StaticObjectsDbContext>(options => options.UseSqlServer(connectionString)); services.AddTransient <Abstractions.IStaticObjectsRepository>( new Func <IServiceProvider, Abstractions.IStaticObjectsRepository>( (provider) => { return(new EfCoreStaticObjectsRepository( provider.GetService <ILogger <EfCoreStaticObjectsRepository> >(), provider.GetService <StaticObjectsDbContext>())); })); services.AddTransient <IServiceAppService>(new Func <IServiceProvider, IServiceAppService>( (provider) => { return(new ServiceAppService(provider.GetService <ILogger <ServiceAppService> >(), provider.GetService <Abstractions.IStaticObjectsRepository>(), provider)); })); services.AddTransient <IStorageService>(new Func <IServiceProvider, IStorageService>( (provider) => { return(new StorageService(provider.GetService <ILogger <StorageService> >(), provider.GetService <Abstractions.IStaticObjectsRepository>(), provider)); })); services.AddTransient <IImageService>(new Func <IServiceProvider, IImageService>( (provider) => { return(new ImageService(provider.GetService <ILogger <ImageService> >(), provider.GetService <IServiceAppService>(), provider.GetService <IStorageService>(), provider.GetService <Abstractions.IStaticObjectsRepository>())); })); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc(options => { }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(setupAction => { setupAction.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; }); //太不稳定了,不加 ////加入ASP.NET Core Elm 功能,记录所有HTTP请求信息 //services.AddElm(); services.AddIdentity <ApplicationUser, ApplicationRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 6; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; }).AddDefaultTokenProviders(); services.AddAuthentication().AddJwtBearer(); string connectionString = Configuration.GetConnectionString( "DefaultConnectionString"); services.AddLogging(configure => { configure.AddNLog(); }); // Identity Services services.AddTransient <IUserStore <ApplicationUser>, EfCoreUserStore>(); services.AddTransient <IRoleStore <ApplicationRole>, EfCoreRoleStore>(); services.AddTransient <ApplicationUserManager>(); services.AddTransient <ApplicationRoleManager>(); services.AddTransient <ApplicationSignInManager>(); services.AddTransient <UserClaimsPrincipalFactory < ApplicationUser, ApplicationRole>, ApplicationUserClaimsPrincipalFactory>(); services.AddTransient <IDbConnection>( impl => new SqlConnection(connectionString) ); //impl => new MySqlConnection(connectionString)); SigningCredentials signingCredentials = new SigningCredentials( new SymmetricSecurityKey(System.Text.Encoding.ASCII.GetBytes( Configuration.GetValue <string>("SigningCredentials:Key"))), SecurityAlgorithms.HmacSha256Signature); services.AddSingleton <SigningCredentials>(signingCredentials); DisconfService disconf = new DisconfService(this.Configuration); disconf.CustomConfigs.Add("Issuer", Configuration.GetValue <string>("SigningCredentials:Issuer")); disconf.CustomConfigs.Add("Audience", Configuration.GetValue <string>("SigningCredentials:Audience")); services.AddSingleton <DisconfService>(disconf); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(connectionString) ); //services.AddDbContext<ApplicationDbContext>(options => // options.UseMySql(connectionString)); services.AddLogging(configure => { configure.AddNLog(); }); }