Skip to content

Commit

Permalink
cache: return support kafka. refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeybannov committed Jan 27, 2022
1 parent e010268 commit 1908af6
Show file tree
Hide file tree
Showing 37 changed files with 85 additions and 59 deletions.
2 changes: 2 additions & 0 deletions common/ASC.Api.Core/ASC.Api.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.13.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion common/ASC.Api.Core/Core/BaseStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using NLog.Extensions.Logging;

using StackExchange.Redis.Extensions.Core.Configuration;
using StackExchange.Redis.Extensions.Newtonsoft;

namespace ASC.Api.Core
{
Expand Down Expand Up @@ -105,10 +106,17 @@ public virtual void ConfigureServices(IServiceCollection services)
DIHelper.TryAdd<WebhooksGlobalFilterAttribute>();

var redisConfiguration = Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
DIHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(redisConfiguration);
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions common/services/ASC.ApiSystem/ASC.ApiSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.ApiSystem/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ public override void ConfigureServices(IServiceCollection services)
services.AddMemoryCache();

var redisConfiguration = Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));
}
Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.ClearEvents/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));
}
Expand Down
2 changes: 0 additions & 2 deletions common/services/ASC.Data.Backup/ASC.Data.Backup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ASC.Data.Backup.Core\ASC.Data.Backup.Core.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions common/services/ASC.Data.Backup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,5 @@ public override void ConfigureServices(IServiceCollection services)
services.AddHostedService<BackupSchedulerService>();
services.AddHostedService<BackupListenerService>();
services.AddHostedService<BackupWorkerService>();

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion common/services/ASC.Data.Storage.Encryption/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public override void ConfigureServices(IServiceCollection services)
DIHelper.TryAdd<EncryptionServiceLauncher>();

services.AddHostedService<EncryptionServiceLauncher>();
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}
}
}
7 changes: 6 additions & 1 deletion common/services/ASC.Data.Storage.Migration/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.Notify/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.Radicale/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.Socket.IO.Svc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.SsoAuth.Svc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.Studio.Notify/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion common/services/ASC.TelegramService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public override void ConfigureServices(IServiceCollection services)
DIHelper.TryAdd<TelegramLauncher>();

services.AddHostedService<TelegramLauncher>();
services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}
}
}
7 changes: 6 additions & 1 deletion common/services/ASC.Thumbnails.Svc/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
7 changes: 6 additions & 1 deletion common/services/ASC.Webhooks.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
3 changes: 1 addition & 2 deletions config/kafka.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"kafka": {
"BootstrapServers": ""
}
}
}
7 changes: 6 additions & 1 deletion products/ASC.CRM/BackgroundTasks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand Down
2 changes: 0 additions & 2 deletions products/ASC.CRM/Server/ASC.CRM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
</PackageReference>
<PackageReference Include="LumenWorksCsvReader" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.Calendar/Server/ASC.Calendar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
<PackageReference Include="Ical.Net" Version="4.1.11" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions products/ASC.Calendar/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public override void ConfigureServices(IServiceCollection services)
DIHelper.TryAdd<CalendarController>();

NotifyConfigurationExtension.Register(DIHelper);

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());

}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
1 change: 0 additions & 1 deletion products/ASC.Files/Server/ASC.Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\ASC.Api.Core\ASC.Api.Core.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.Files/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public override void ConfigureServices(IServiceCollection services)
DIHelper.TryAdd<ThirdPartyAppHandlerService>();

NotifyConfigurationExtension.Register(DIHelper);

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
8 changes: 7 additions & 1 deletion products/ASC.Files/Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
var diHelper = new DIHelper(services);

var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();

if (redisConfiguration != null)
if (kafkaConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCache<>));
}
else if (redisConfiguration != null)
{
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCache<>));

Expand All @@ -89,6 +94,7 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
}


diHelper.RegisterProducts(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);

if (!bool.TryParse(hostContext.Configuration["disable_elastic"], out var disableElastic))
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.Mail/Server/ASC.Mail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.Mail/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public override void ConfigureServices(IServiceCollection services)
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

base.ConfigureServices(services);

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.People/Server/ASC.People.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.People/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public override void ConfigureServices(IServiceCollection services)

DIHelper.TryAdd<PeopleController>();
DIHelper.TryAdd<GroupController>();

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}
}
}
1 change: 0 additions & 1 deletion products/ASC.Projects/Server/ASC.Projects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions products/ASC.Projects/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public override void ConfigureServices(IServiceCollection services)
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

base.ConfigureServices(services);

services.AddStackExchangeRedisExtensions<NewtonsoftSerializer>(Configuration.GetSection("Redis").Get<RedisConfiguration>());
}

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
Expand Down
2 changes: 0 additions & 2 deletions web/ASC.Web.Api/ASC.Web.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1" />
<PackageReference Include="StackExchange.Redis.Extensions.Newtonsoft" Version="7.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 1908af6

Please sign in to comment.