Ejemplo n.º 1
0
        /// <summary>
        /// 增加 BootstrapBlazor 服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureOptions"></param>
        /// <param name="setupAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddBootstrapBlazor(this IServiceCollection services, Action <BootstrapBlazorOptions>?configureOptions = null, Action <JsonLocalizationOptions>?setupAction = null)
        {
            services.AddJsonLocalization(setupAction);
            services.AddSingleton <IComponentIdGenerator, DefaultIdGenerator>();
            services.AddSingleton <ITableExcelExport, DefaultExcelExport>();
            services.AddScoped <DialogService>();
            services.AddScoped <MessageService>();
            services.AddScoped <PopoverService>();
            services.AddScoped <ToastService>();
            services.AddScoped <SwalService>();
            services.AddScoped <MenuTabBoundleOptions>();
            services.AddSingleton <IConfigureOptions <BootstrapBlazorOptions>, ConfigureOptions <BootstrapBlazorOptions> >();
            services.Configure <BootstrapBlazorOptions>(options =>
            {
                configureOptions?.Invoke(options);

                // fix(#I2925C): https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I2925C
                if (CultureInfo.CurrentUICulture.Name == "en" || !options.SupportedCultures.Any(c => c.Equals(CultureInfo.CurrentUICulture.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    CultureInfo.CurrentUICulture = new CultureInfo(options.DefaultUICultureInfoName ?? "en-US");
                }
            });

            ServiceProviderHelper.RegisterService(services);

            return(services);
        }
 /// <summary>
 /// 增加 BootstrapBlazor 服务
 /// </summary>
 /// <param name="services"></param>
 /// <param name="configureOptions"></param>
 /// <param name="setupAction"></param>
 /// <returns></returns>
 public static IServiceCollection AddBootstrapBlazor(this IServiceCollection services, Action<BootstrapBlazorOptions>? configureOptions = null, Action<JsonLocalizationOptions>? setupAction = null)
 {
     services.AddAuthorizationCore();
     services.AddJsonLocalization(setupAction);
     services.TryAddScoped<IComponentIdGenerator, DefaultIdGenerator>();
     services.TryAddScoped<ITableExcelExport, DefaultExcelExport>();
     services.TryAddScoped(typeof(IDataService<>), typeof(NullDataService<>));
     services.TryAddScoped<DialogService>();
     services.TryAddScoped<MessageService>();
     services.TryAddScoped<PopoverService>();
     services.TryAddScoped<ToastService>();
     services.TryAddScoped<SwalService>();
     services.TryAddScoped<TabItemTextOptions>();
     services.TryAddSingleton<IConfigureOptions<BootstrapBlazorOptions>, ConfigureOptions<BootstrapBlazorOptions>>();
     services.Configure<BootstrapBlazorOptions>(options =>
     {
         configureOptions?.Invoke(options);
     });
     ServiceProviderHelper.RegisterService(services);
     return services;
 }