Esempio n. 1
0
 /// <summary>
 /// 添加服务。
 /// </summary>
 /// <param name="builder">服务构建实例。</param>
 public void ConfigureServices(IServiceBuilder builder)
 {
     builder.AddSettings()
     .AddScoped(services => services.GetRequiredService <ISettingsManager>().GetSettings <SkinSettings>())
     .AddScoped(services => services.GetRequiredService <ISettingsManager>().GetSettings <SiteSettings>());
     builder.AddSqlServer()
     .AddModelUI <User>()   //添加用户模型应用
     .AddOpenServices <User>()
     .AddServices(services =>
     {
         services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
         .AddPermissionAuthorization()    //添加权限验证
         .AddCookie(options =>
         {
             options.LoginPath = new PathString("/login");
         });
         services.AddControllers();
         services.AddRazorPages(options =>
         {
             options.AddCultureLocalizationOptions();
             options.Conventions.AuthorizeFolder("/admin");
             options.Conventions.AuthorizeFolder("/account");
         });
     });
 }
Esempio n. 2
0
 /// <summary>
 /// 添加配置组件。
 /// </summary>
 /// <param name="builder">服务构建实例对象。</param>
 /// <returns>返回服务构建实例对象。</returns>
 public static IServiceBuilder AddUserSettings(this IServiceBuilder builder)
 {
     builder.AddSettings()
     .AddScoped <Settings.ISettingsManager, Settings.SettingsManager>()
     .AddTransients <IDataMigration, DefaultSettingsDataMigration>();
     return(builder);
 }
 /// <summary>
 /// 添加字典组件。
 /// </summary>
 /// <param name="builder">服务构建实例。</param>
 /// <param name="includeDictionary">是否组成字典实例。</param>
 /// <returns>服务构建实例。</returns>
 public static IServiceBuilder AddSettings(this IServiceBuilder builder, bool includeDictionary = false)
 {
     builder.AddServices(services =>
     {
         services.TryAddEnumerable(ServiceDescriptor
                                   .Transient <IDataMigration, SettingsDataMigration>());
         services.TryAddSingleton <ISettingsManager, SettingsManager>();
     });
     if (includeDictionary)
     {
         builder.AddSettings <SettingDictionaryManager>();
     }
     return(builder);
 }