Added DI for Voip

This commit is contained in:
pavelbannov 2020-04-17 17:07:44 +03:00
parent f5e90209b9
commit c5ff09ac09
4 changed files with 46 additions and 10 deletions

View File

@ -26,6 +26,7 @@
using System;
using ASC.Core;
using ASC.Core.Common.EF;
using ASC.Core.Common.EF.Context;
@ -37,10 +38,10 @@ namespace ASC.VoipService.Dao
protected VoipDbContext VoipDbContext { get; set; }
protected AbstractDao(DbContextManager<VoipDbContext> dbOptions, int tenantID)
protected AbstractDao(DbContextManager<VoipDbContext> dbOptions, TenantManager tenantManager)
{
VoipDbContext = dbOptions.Get(dbid);
TenantID = tenantID;
TenantID = tenantManager.GetCurrentTenant().TenantId;
}
protected int TenantID

View File

@ -29,6 +29,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Core;
using ASC.Core.Common;
@ -65,7 +66,7 @@ namespace ASC.VoipService.Dao
public VoipDaoCache VoipDaoCache { get; }
public CachedVoipDao(
int tenantID,
TenantManager tenantManager,
DbContextManager<VoipDbContext> dbOptions,
AuthContext authContext,
TenantUtil tenantUtil,
@ -73,7 +74,7 @@ namespace ASC.VoipService.Dao
BaseCommonLinkUtility baseCommonLinkUtility,
ConsumerFactory consumerFactory,
VoipDaoCache voipDaoCache)
: base(tenantID, dbOptions, authContext, tenantUtil, securityContext, baseCommonLinkUtility, consumerFactory)
: base(tenantManager, dbOptions, authContext, tenantUtil, securityContext, baseCommonLinkUtility, consumerFactory)
{
cache = voipDaoCache.Cache;
VoipDaoCache = voipDaoCache;
@ -108,5 +109,22 @@ namespace ASC.VoipService.Dao
{
return "voip" + tenant.ToString(CultureInfo.InvariantCulture);
}
}
public static class VoipDaoExtention
{
public static DIHelper AddVoipDaoService(this DIHelper services)
{
services.TryAddScoped<VoipDao, CachedVoipDao>();
services.TryAddSingleton<VoipDaoCache>();
return services
.AddDbContextManagerService<VoipDbContext>()
.AddAuthContextService()
.AddTenantUtilService()
.AddSecurityContextService()
.AddBaseCommonLinkUtilityService()
.AddConsumerFactoryService();
}
}
}

View File

@ -42,14 +42,14 @@ namespace ASC.VoipService.Dao
public class VoipDao : AbstractDao
{
public VoipDao(
int tenantID,
TenantManager tenantManager,
DbContextManager<VoipDbContext> dbOptions,
AuthContext authContext,
TenantUtil tenantUtil,
SecurityContext securityContext,
BaseCommonLinkUtility baseCommonLinkUtility,
ConsumerFactory consumerFactory)
: base(dbOptions, tenantID)
: base(dbOptions, tenantManager)
{
AuthContext = authContext;
TenantUtil = tenantUtil;

View File

@ -389,6 +389,8 @@ namespace ASC.Web.Core.Sms
set { }
}
public VoipDao VoipDao { get; }
public override bool Enable()
{
return
@ -425,6 +427,7 @@ namespace ASC.Web.Core.Sms
}
public TwilioProvider(
VoipDao voipDao,
TenantManager tenantManager,
CoreBaseSettings coreBaseSettings,
CoreSettings coreSettings,
@ -434,6 +437,7 @@ namespace ASC.Web.Core.Sms
string name, int order, Dictionary<string, string> props, Dictionary<string, string> additional = null)
: base(tenantManager, coreBaseSettings, coreSettings, configuration, cache, options, name, order, props, additional)
{
VoipDao = voipDao;
}
@ -456,12 +460,11 @@ namespace ASC.Web.Core.Sms
var provider = new VoipService.Twilio.TwilioProvider(Key, Secret, authContext, tenantUtil, securityContext, baseCommonLinkUtility);
var dao = new CachedVoipDao(tenantManager.GetCurrentTenant().TenantId, dbOptions, authContext, tenantUtil, securityContext, baseCommonLinkUtility, ConsumerFactory, voipDaoCache);
var numbers = dao.GetNumbers();
var numbers = VoipDao.GetNumbers();
foreach (var number in numbers)
{
provider.DisablePhone(number);
dao.DeleteNumber(number.Id);
VoipDao.DeleteNumber(number.Id);
}
}
}
@ -473,6 +476,7 @@ namespace ASC.Web.Core.Sms
}
public TwilioSaaSProvider(
VoipDao voipDao,
TenantManager tenantManager,
CoreBaseSettings coreBaseSettings,
CoreSettings coreSettings,
@ -480,8 +484,21 @@ namespace ASC.Web.Core.Sms
ICacheNotify<ConsumerCacheItem> cache,
IOptionsMonitor<ILog> options,
string name, int order, Dictionary<string, string> additional = null)
: base(tenantManager, coreBaseSettings, coreSettings, configuration, cache, options, name, order, null, additional)
: base(voipDao, tenantManager, coreBaseSettings, coreSettings, configuration, cache, options, name, order, null, additional)
{
}
}
public static class TwilioProviderExtention
{
public static DIHelper AddTwilioProviderService(this DIHelper services)
{
services.TryAddScoped<TwilioProvider>();
services.TryAddScoped<TwilioSaaSProvider>();
return services.AddVoipDaoService()
.AddTenantManagerService()
.AddCoreBaseSettingsService()
.AddCoreSettingsService();
}
}
}