Storage: DI singleton
This commit is contained in:
parent
b34ba4b016
commit
4d440232f2
@ -2,17 +2,15 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ASC.Common.Utils;
|
using ASC.Common.Utils;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace ASC.Data.Storage.Configuration
|
namespace ASC.Data.Storage.Configuration
|
||||||
{
|
{
|
||||||
public static class StorageConfigFactory
|
public static class StorageConfigFactory
|
||||||
{
|
{
|
||||||
public static Storage Instance
|
public static IServiceCollection AddStorage(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
get
|
return services.AddSingleton(r => ConfigurationManager.GetSetting<Storage>("Storage"));
|
||||||
{
|
|
||||||
return ConfigurationManager.GetSetting<Storage>("Storage");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ using System.Threading.Tasks;
|
|||||||
using Amazon;
|
using Amazon;
|
||||||
using Amazon.S3;
|
using Amazon.S3;
|
||||||
using Amazon.S3.Model;
|
using Amazon.S3.Model;
|
||||||
|
using ASC.Common.DependencyInjection;
|
||||||
using ASC.Core;
|
using ASC.Core;
|
||||||
using ASC.Data.Storage.Configuration;
|
|
||||||
|
|
||||||
namespace ASC.Data.Storage.S3
|
namespace ASC.Data.Storage.S3
|
||||||
{
|
{
|
||||||
@ -121,7 +121,7 @@ namespace ASC.Data.Storage.S3
|
|||||||
{
|
{
|
||||||
if (!configured)
|
if (!configured)
|
||||||
{
|
{
|
||||||
var config = StorageConfigFactory.Instance;
|
var config = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
var handler = config.GetHandler("s3");
|
var handler = config.GetHandler("s3");
|
||||||
if (handler != null)
|
if (handler != null)
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Configuration;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using ASC.Common.Caching;
|
using ASC.Common.Caching;
|
||||||
@ -35,8 +33,6 @@ using ASC.Core;
|
|||||||
using ASC.Data.Storage.Configuration;
|
using ASC.Data.Storage.Configuration;
|
||||||
using ASC.Core.Common.Configuration;
|
using ASC.Core.Common.Configuration;
|
||||||
using ASC.Data.Storage.DiscStorage;
|
using ASC.Data.Storage.DiscStorage;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using ASC.Common.DependencyInjection;
|
using ASC.Common.DependencyInjection;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
||||||
@ -83,7 +79,7 @@ namespace ASC.Data.Storage
|
|||||||
var store = DataStoreCache.Get(tenant, module);
|
var store = DataStoreCache.Get(tenant, module);
|
||||||
if (store == null)
|
if (store == null)
|
||||||
{
|
{
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
if (section == null)
|
if (section == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("config section not found");
|
throw new InvalidOperationException("config section not found");
|
||||||
@ -103,7 +99,7 @@ namespace ASC.Data.Storage
|
|||||||
//Make tennant path
|
//Make tennant path
|
||||||
tenant = TennantPath.CreatePath(tenant);
|
tenant = TennantPath.CreatePath(tenant);
|
||||||
|
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
if (section == null)
|
if (section == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("config section not found");
|
throw new InvalidOperationException("config section not found");
|
||||||
@ -116,7 +112,7 @@ namespace ASC.Data.Storage
|
|||||||
|
|
||||||
public static IEnumerable<string> GetModuleList(string configpath, bool exceptDisabledMigration = false)
|
public static IEnumerable<string> GetModuleList(string configpath, bool exceptDisabledMigration = false)
|
||||||
{
|
{
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
return section.Module
|
return section.Module
|
||||||
.Where(x => x.Visible)
|
.Where(x => x.Visible)
|
||||||
.Where(x=> !exceptDisabledMigration || !x.DisableMigrate)
|
.Where(x=> !exceptDisabledMigration || !x.DisableMigrate)
|
||||||
@ -125,7 +121,7 @@ namespace ASC.Data.Storage
|
|||||||
|
|
||||||
public static IEnumerable<string> GetDomainList(string configpath, string modulename)
|
public static IEnumerable<string> GetDomainList(string configpath, string modulename)
|
||||||
{
|
{
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
if (section == null)
|
if (section == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("config section not found");
|
throw new ArgumentException("config section not found");
|
||||||
@ -146,7 +142,7 @@ namespace ASC.Data.Storage
|
|||||||
// throw new InvalidOperationException("Application not hosted.");
|
// throw new InvalidOperationException("Application not hosted.");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
if (section != null)
|
if (section != null)
|
||||||
{
|
{
|
||||||
//old scheme
|
//old scheme
|
||||||
@ -224,7 +220,7 @@ namespace ASC.Data.Storage
|
|||||||
|
|
||||||
private static IDataStore GetDataStore(string tenant, string module, DataStoreConsumer consumer, IQuotaController controller)
|
private static IDataStore GetDataStore(string tenant, string module, DataStoreConsumer consumer, IQuotaController controller)
|
||||||
{
|
{
|
||||||
var storage = StorageConfigFactory.Instance;
|
var storage = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
var moduleElement = storage.GetModuleElement(module);
|
var moduleElement = storage.GetModuleElement(module);
|
||||||
if (moduleElement == null)
|
if (moduleElement == null)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,7 @@ namespace ASC.Data.Storage
|
|||||||
|
|
||||||
static WebPath()
|
static WebPath()
|
||||||
{
|
{
|
||||||
var section = StorageConfigFactory.Instance;
|
var section = CommonServiceProvider.GetService<Configuration.Storage>();
|
||||||
if (section != null)
|
if (section != null)
|
||||||
{
|
{
|
||||||
Appenders = section.Appender;
|
Appenders = section.Appender;
|
||||||
|
@ -22,6 +22,7 @@ using ASC.Core.Common;
|
|||||||
using ASC.Common;
|
using ASC.Common;
|
||||||
using ASC.Common.DependencyInjection;
|
using ASC.Common.DependencyInjection;
|
||||||
using ASC.Web.Core;
|
using ASC.Web.Core;
|
||||||
|
using ASC.Data.Storage.Configuration;
|
||||||
|
|
||||||
namespace ASC.Web.Api
|
namespace ASC.Web.Api
|
||||||
{
|
{
|
||||||
@ -65,8 +66,9 @@ namespace ASC.Web.Api
|
|||||||
builder.AddApplicationPart(a);
|
builder.AddApplicationPart(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
services.AddLogManager(Configuration);
|
services.AddLogManager(Configuration)
|
||||||
services.AddWebItemManager();
|
.AddStorage()
|
||||||
|
.AddWebItemManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
@ -2,6 +2,7 @@ using ASC.Common.DependencyInjection;
|
|||||||
using ASC.Common.Logging;
|
using ASC.Common.Logging;
|
||||||
using ASC.Common.Utils;
|
using ASC.Common.Utils;
|
||||||
using ASC.Data.Storage;
|
using ASC.Data.Storage;
|
||||||
|
using ASC.Data.Storage.Configuration;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
|
using Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer;
|
||||||
@ -40,6 +41,7 @@ namespace ASC.Web.Studio
|
|||||||
});
|
});
|
||||||
|
|
||||||
services.AddHttpContextAccessor()
|
services.AddHttpContextAccessor()
|
||||||
|
.AddStorage()
|
||||||
.AddLogManager(Configuration);
|
.AddLogManager(Configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user