Exemple #1
0
        /// <summary>
        /// 更改ocelot的存储方式为使用EF
        /// </summary>
        /// <param name="ocelotBuilder"></param>
        /// <returns></returns>
        public static IOcelotBuilder AddOcelotEFCache(this IOcelotBuilder ocelotBuilder, Action <CacheOptions> options)
        {
            //获取数据
            CacheOptions cacheOptions = new CacheOptions();

            options?.Invoke(cacheOptions);

            OcelotEFOption eFOptions = new OcelotEFOption();

            cacheOptions?.EFOptions.Invoke(eFOptions);

            #region  注入仓储

            ocelotBuilder.Services.AddRepository();

            ocelotBuilder.Services.AddEFOption(ocelot =>
            {
                ocelot.ConfigureDbContext       = eFOptions.ConfigureDbContext;
                ocelot.ReadOnlyConnectionString = eFOptions.ReadOnlyConnectionString;
                //
                ocelot.UseEntityFramework <OcelotDbContent, SlaveOcelotDbContent>();
                ocelot.IsOpenMasterSlave = eFOptions.IsOpenMasterSlave;
            });

            #endregion

            //更改扩展方式
            ocelotBuilder.Services.RemoveAll(typeof(IFileConfigurationRepository));
            //重写提取Ocelot配置信息
            ocelotBuilder.Services.AddSingleton(EFConfigurationProvider.Get);
            ocelotBuilder.Services.AddSingleton <IFileConfigurationRepository, EFConfigurationRepository>();
            return(ocelotBuilder);
        }
Exemple #2
0
 /// <summary>
 /// 注入ocelot仓储服务
 /// </summary>
 /// <param name="services"></param>
 /// <param name="ocelotEFOption"></param>
 /// <returns></returns>
 private static IServiceCollection AddOcelotRepository(this IServiceCollection services, OcelotEFOption ocelotEFOption)
 {
     services.AddRepository()
     .AddEFOption(configureOptions =>
     {
         configureOptions.ConfigureDbContext = ocelotEFOption.ConfigureDbContext;
         configureOptions.UseEntityFramework <ConfigurationDbContent, SlaveConfigurationDbContent>();
         configureOptions.IsOpenMasterSlave        = ocelotEFOption.IsOpenMasterSlave;
         configureOptions.ReadOnlyConnectionString = ocelotEFOption.ReadOnlyConnectionString;
     });
     return(services);
 }
Exemple #3
0
 /// <summary>
 /// 注入配置界面
 /// </summary>
 /// <param name="mvcBuilder"></param>
 /// <returns></returns>
 public static IMvcCoreBuilder AddConfigurationManagement(this IMvcCoreBuilder mvcBuilder, OcelotEFOption ocelotEFOption, Action <ConfigurationOptions> option)
 {
     mvcBuilder.Services.Configure(option);
     mvcBuilder.AddConfigurationManagement(ocelotEFOption);
     return(mvcBuilder);
 }
Exemple #4
0
 /// <summary>
 /// 注入配置界面
 /// </summary>
 /// <param name="mvcBuilder"></param>
 /// <returns></returns>
 public static IMvcCoreBuilder AddConfigurationManagement(this IMvcCoreBuilder mvcBuilder, OcelotEFOption ocelotEFOption)
 {
     mvcBuilder.Services.AddOcelotRepository(ocelotEFOption);
     mvcBuilder.Services.AddServices();
     //注入mvc扩展
     mvcBuilder.ConfigureApplicationPartManager(a =>
     {
         a.ApplicationParts.Add(new AssemblyPart(typeof(ConfigurationExtensions).Assembly));
     });
     return(mvcBuilder);
 }