From 1c2cd83284fc121faea06213eb5393ea87f07240 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Tue, 28 May 2019 18:05:20 +0300 Subject: [PATCH 1/4] Added autofac and nlog --- common/ASC.Common/Logging/Log.cs | 21 +++++++++++---------- web/ASC.Web.Api/ASC.Web.Api.csproj | 8 +++++--- web/ASC.Web.Api/Program.cs | 8 ++++++-- web/ASC.Web.Api/Startup.cs | 19 +++++++++++++++++-- web/ASC.Web.Api/autofac.json | 12 ++++++++++++ web/ASC.Web.Api/nlog.config | 30 ++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 web/ASC.Web.Api/autofac.json create mode 100644 web/ASC.Web.Api/nlog.config diff --git a/common/ASC.Common/Logging/Log.cs b/common/ASC.Common/Logging/Log.cs index c90dfa263f..f530c54c43 100644 --- a/common/ASC.Common/Logging/Log.cs +++ b/common/ASC.Common/Logging/Log.cs @@ -32,7 +32,7 @@ using ASC.Common.DependencyInjection; using Autofac; using log4net.Config; using log4net.Core; -using log4net.Util; +using Microsoft.Extensions.Configuration; using NLog; namespace ASC.Common.Logging @@ -754,27 +754,28 @@ namespace ASC.Common.Logging public class LogManager { - internal static IContainer Builder { get; set; } + internal IContainer Builder { get; set; } internal static ConcurrentDictionary Logs; static LogManager() { - var container = AutofacConfigLoader.Load("core"); - if (container != null) - { - Builder = container.Build(); - } - Logs = new ConcurrentDictionary(); } + + public LogManager(IContainer builder) + { + Builder = builder; + } public static ILog GetLogger(string name) - { + { + var logManager = CommonServiceProvider.GetService(); + ILog result; if (!Logs.TryGetValue(name, out result)) { - result = Logs.AddOrUpdate(name, Builder != null ? Builder.Resolve(new TypedParameter(typeof(string), name)) : new NullLog(), (k, v) => v); + result = Logs.AddOrUpdate(name, logManager.Builder != null ? logManager.Builder.Resolve(new TypedParameter(typeof(string), name)) : new NullLog(), (k, v) => v); } return result; diff --git a/web/ASC.Web.Api/ASC.Web.Api.csproj b/web/ASC.Web.Api/ASC.Web.Api.csproj index a9541a0d53..a902287c7d 100644 --- a/web/ASC.Web.Api/ASC.Web.Api.csproj +++ b/web/ASC.Web.Api/ASC.Web.Api.csproj @@ -5,6 +5,7 @@ + @@ -13,11 +14,12 @@ + - - - + + + diff --git a/web/ASC.Web.Api/Program.cs b/web/ASC.Web.Api/Program.cs index 4770edb98e..aab87731e5 100644 --- a/web/ASC.Web.Api/Program.cs +++ b/web/ASC.Web.Api/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; - +using Microsoft.Extensions.Configuration; + namespace ASC.Web.Api { public class Program @@ -15,6 +16,9 @@ namespace ASC.Web.Api .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); - }); + }) + .ConfigureAppConfiguration((hostingContext, config) => { + config.AddJsonFile("autofac.json"); + }); } } diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 0d5a9d275a..83e7a3af68 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -8,20 +8,26 @@ using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; + +using ASC.Common.Logging; using ASC.Web.Api.Handlers; using ASC.Web.Api.Middleware; +using Autofac; +using Autofac.Configuration; + + namespace ASC.Web.Api { public class Startup { + public IConfiguration Configuration { get; } + public Startup(IConfiguration configuration) { Configuration = configuration; } - public IConfiguration Configuration { get; } - public void ConfigureServices(IServiceCollection services) { services.AddControllers() @@ -38,6 +44,15 @@ namespace ASC.Web.Api config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter))); config.Filters.Add(new AuthorizeFilter(policy)); }); + + var module = new ConfigurationModule(Configuration); + var builder = new ContainerBuilder(); + builder.RegisterModule(module); + + var container = builder.Build(); + + services.AddSingleton(container); + services.AddSingleton(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/web/ASC.Web.Api/autofac.json b/web/ASC.Web.Api/autofac.json new file mode 100644 index 0000000000..ccfe87ecaa --- /dev/null +++ b/web/ASC.Web.Api/autofac.json @@ -0,0 +1,12 @@ +{ + "components": [ + { + "type": "ASC.Common.Logging.LogNLog, ASC.Common", + "services": [ + { + "type": "ASC.Common.Logging.ILog, ASC.Common" + } + ] + } + ] +} diff --git a/web/ASC.Web.Api/nlog.config b/web/ASC.Web.Api/nlog.config new file mode 100644 index 0000000000..f838503156 --- /dev/null +++ b/web/ASC.Web.Api/nlog.config @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f76bb1e7d6b8aa4915486b495a2606c42c66fb94 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Tue, 28 May 2019 18:24:38 +0300 Subject: [PATCH 2/4] LogExtension moved to ASC.Common --- common/ASC.Common/ASC.Common.csproj | 2 ++ common/ASC.Common/Logging/Log.cs | 19 +++++++++++++++++++ web/ASC.Web.Api/ASC.Web.Api.csproj | 2 -- web/ASC.Web.Api/Startup.cs | 12 +----------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/common/ASC.Common/ASC.Common.csproj b/common/ASC.Common/ASC.Common.csproj index cfaeba4fcb..a09385ac64 100644 --- a/common/ASC.Common/ASC.Common.csproj +++ b/common/ASC.Common/ASC.Common.csproj @@ -34,6 +34,7 @@ + @@ -46,6 +47,7 @@ + diff --git a/common/ASC.Common/Logging/Log.cs b/common/ASC.Common/Logging/Log.cs index f530c54c43..6243e89a0e 100644 --- a/common/ASC.Common/Logging/Log.cs +++ b/common/ASC.Common/Logging/Log.cs @@ -30,9 +30,11 @@ using System.Collections.Generic; using System.Reflection; using ASC.Common.DependencyInjection; using Autofac; +using Autofac.Configuration; using log4net.Config; using log4net.Core; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using NLog; namespace ASC.Common.Logging @@ -780,5 +782,22 @@ namespace ASC.Common.Logging return result; } + } + + public static class LogExtension + { + public static IServiceCollection AddLogManager(this IServiceCollection services, IConfiguration configuration) + { + var module = new ConfigurationModule(configuration); + var builder = new ContainerBuilder(); + builder.RegisterModule(module); + + var container = builder.Build(); + + services.AddSingleton(container) + .AddSingleton(); + + return services; + } } } diff --git a/web/ASC.Web.Api/ASC.Web.Api.csproj b/web/ASC.Web.Api/ASC.Web.Api.csproj index a902287c7d..08a0dea16f 100644 --- a/web/ASC.Web.Api/ASC.Web.Api.csproj +++ b/web/ASC.Web.Api/ASC.Web.Api.csproj @@ -5,7 +5,6 @@ - @@ -14,7 +13,6 @@ - diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 83e7a3af68..2da17e40cf 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -13,9 +13,6 @@ using ASC.Common.Logging; using ASC.Web.Api.Handlers; using ASC.Web.Api.Middleware; -using Autofac; -using Autofac.Configuration; - namespace ASC.Web.Api { @@ -45,14 +42,7 @@ namespace ASC.Web.Api config.Filters.Add(new AuthorizeFilter(policy)); }); - var module = new ConfigurationModule(Configuration); - var builder = new ContainerBuilder(); - builder.RegisterModule(module); - - var container = builder.Build(); - - services.AddSingleton(container); - services.AddSingleton(); + services.AddLogManager(Configuration); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) From c2d61517a56a2810229580fe179614349420e1b1 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Wed, 29 May 2019 17:44:37 +0300 Subject: [PATCH 3/4] Added ASC.Api.Core.csproj added build.bat PeopleController replaced to ASC.People --- ASC.Web.sln | 98 +++++++++++-------- build/build.bat | 14 +++ common/ASC.Api.Core/ASC.Api.Core.csproj | 15 +++ .../Handlers/CookieAuthHandler.cs | 0 .../Middleware/ResponseWrapper.cs | 1 + .../Properties/launchSettings.json | 27 +++++ .../ASC.Api.Core}/Routing/DefaultRoute.cs | 0 .../ASC.Api.Core}/Routing/FormatIndexRoute.cs | 0 .../ASC.Api.Core}/Routing/FormatRoute.cs | 0 products/ASC.People/ASC.People.csproj | 5 + .../Controllers/PeopleController.cs | 0 .../Controllers/SampleDataController.cs | 44 --------- .../ASC.People}/Models/EmployeeWraper.cs | 0 products/ASC.People/Program.cs | 6 -- .../ASC.People/appsettings.Development.json | 9 -- products/ASC.People/appsettings.json | 8 -- web/ASC.Web.Api/ASC.Web.Api.csproj | 6 +- web/ASC.Web.Api/Startup.cs | 14 ++- 18 files changed, 130 insertions(+), 117 deletions(-) create mode 100644 build/build.bat create mode 100644 common/ASC.Api.Core/ASC.Api.Core.csproj rename {web/ASC.Web.Api => common/ASC.Api.Core}/Handlers/CookieAuthHandler.cs (100%) rename {web/ASC.Web.Api => common/ASC.Api.Core}/Middleware/ResponseWrapper.cs (96%) create mode 100644 common/ASC.Api.Core/Properties/launchSettings.json rename {web/ASC.Web.Api => common/ASC.Api.Core}/Routing/DefaultRoute.cs (100%) rename {web/ASC.Web.Api => common/ASC.Api.Core}/Routing/FormatIndexRoute.cs (100%) rename {web/ASC.Web.Api => common/ASC.Api.Core}/Routing/FormatRoute.cs (100%) rename {web/ASC.Web.Api => products/ASC.People}/Controllers/PeopleController.cs (100%) delete mode 100644 products/ASC.People/Controllers/SampleDataController.cs rename {web/ASC.Web.Api => products/ASC.People}/Models/EmployeeWraper.cs (100%) delete mode 100644 products/ASC.People/appsettings.Development.json delete mode 100644 products/ASC.People/appsettings.json diff --git a/ASC.Web.sln b/ASC.Web.sln index 9adb09e200..26d884dda0 100644 --- a/ASC.Web.sln +++ b/ASC.Web.sln @@ -1,43 +1,55 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28803.202 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Studio", "web\ASC.Web.Studio\ASC.Web.Studio.csproj", "{90183112-BCD6-4E16-9CA2-12231930DAB4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Api", "web\ASC.Web.Api\ASC.Web.Api.csproj", "{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Common", "common\ASC.Common\ASC.Common.csproj", "{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Core.Common", "common\ASC.Core.Common\ASC.Core.Common.csproj", "{A51D0454-4AFA-46DE-89D4-B03D37E1816C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.Build.0 = Release|Any CPU - {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.Build.0 = Release|Any CPU - {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.Build.0 = Release|Any CPU - {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {62783077-E041-40BA-A406-E7EF12CAFF2D} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.202 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Studio", "web\ASC.Web.Studio\ASC.Web.Studio.csproj", "{90183112-BCD6-4E16-9CA2-12231930DAB4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Web.Api", "web\ASC.Web.Api\ASC.Web.Api.csproj", "{4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Common", "common\ASC.Common\ASC.Common.csproj", "{EB8F47B3-39DE-4B7D-8EC6-01726368B45D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Core.Common", "common\ASC.Core.Common\ASC.Core.Common.csproj", "{A51D0454-4AFA-46DE-89D4-B03D37E1816C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.People", "products\ASC.People\ASC.People.csproj", "{BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASC.Api.Core", "common\ASC.Api.Core\ASC.Api.Core.csproj", "{62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90183112-BCD6-4E16-9CA2-12231930DAB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90183112-BCD6-4E16-9CA2-12231930DAB4}.Release|Any CPU.Build.0 = Release|Any CPU + {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4AA9F8E3-2F48-44DA-B6C5-37ED7A4739C1}.Release|Any CPU.Build.0 = Release|Any CPU + {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB8F47B3-39DE-4B7D-8EC6-01726368B45D}.Release|Any CPU.Build.0 = Release|Any CPU + {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A51D0454-4AFA-46DE-89D4-B03D37E1816C}.Release|Any CPU.Build.0 = Release|Any CPU + {BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE4816E7-7CD2-4D9B-ABC6-D9E5C04E3926}.Release|Any CPU.Build.0 = Release|Any CPU + {62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62C49C91-1A5A-4C0D-A3B3-A9AE8C9718CE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {62783077-E041-40BA-A406-E7EF12CAFF2D} + EndGlobalSection +EndGlobal diff --git a/build/build.bat b/build/build.bat new file mode 100644 index 0000000000..a7a4916b2f --- /dev/null +++ b/build/build.bat @@ -0,0 +1,14 @@ +PUSHD %~dp0 +echo "ASC.Web.Components" +cd ../web/ASC.Web.Components +call npm install + +echo "ASC.Web.sln" +cd ../../ +call dotnet build ASC.Web.sln + +echo "ASC.People" +call dotnet publish products/ASC.People --self-contained -r win10-x64 -o build/deploy + +echo "ASC.Web.Api" +call dotnet publish web/ASC.Web.Api --self-contained -r win10-x64 -o build/deploy \ No newline at end of file diff --git a/common/ASC.Api.Core/ASC.Api.Core.csproj b/common/ASC.Api.Core/ASC.Api.Core.csproj new file mode 100644 index 0000000000..70bbadfa74 --- /dev/null +++ b/common/ASC.Api.Core/ASC.Api.Core.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.0 + + Library + + + + + + + + + diff --git a/web/ASC.Web.Api/Handlers/CookieAuthHandler.cs b/common/ASC.Api.Core/Handlers/CookieAuthHandler.cs similarity index 100% rename from web/ASC.Web.Api/Handlers/CookieAuthHandler.cs rename to common/ASC.Api.Core/Handlers/CookieAuthHandler.cs diff --git a/web/ASC.Web.Api/Middleware/ResponseWrapper.cs b/common/ASC.Api.Core/Middleware/ResponseWrapper.cs similarity index 96% rename from web/ASC.Web.Api/Middleware/ResponseWrapper.cs rename to common/ASC.Api.Core/Middleware/ResponseWrapper.cs index bb20ff8303..c82cf3fcd5 100644 --- a/web/ASC.Web.Api/Middleware/ResponseWrapper.cs +++ b/common/ASC.Api.Core/Middleware/ResponseWrapper.cs @@ -29,6 +29,7 @@ namespace ASC.Web.Api.Middleware var currentBody = context.Response.Body; using var memoryStream = new MemoryStream(); + context.Response.Body = memoryStream; await next(context); diff --git a/common/ASC.Api.Core/Properties/launchSettings.json b/common/ASC.Api.Core/Properties/launchSettings.json new file mode 100644 index 0000000000..125fe58e42 --- /dev/null +++ b/common/ASC.Api.Core/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:65458/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "ASC.Api.Core": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:65459/" + } + } +} \ No newline at end of file diff --git a/web/ASC.Web.Api/Routing/DefaultRoute.cs b/common/ASC.Api.Core/Routing/DefaultRoute.cs similarity index 100% rename from web/ASC.Web.Api/Routing/DefaultRoute.cs rename to common/ASC.Api.Core/Routing/DefaultRoute.cs diff --git a/web/ASC.Web.Api/Routing/FormatIndexRoute.cs b/common/ASC.Api.Core/Routing/FormatIndexRoute.cs similarity index 100% rename from web/ASC.Web.Api/Routing/FormatIndexRoute.cs rename to common/ASC.Api.Core/Routing/FormatIndexRoute.cs diff --git a/web/ASC.Web.Api/Routing/FormatRoute.cs b/common/ASC.Api.Core/Routing/FormatRoute.cs similarity index 100% rename from web/ASC.Web.Api/Routing/FormatRoute.cs rename to common/ASC.Api.Core/Routing/FormatRoute.cs diff --git a/products/ASC.People/ASC.People.csproj b/products/ASC.People/ASC.People.csproj index 49be6ad1a8..89d2f24819 100644 --- a/products/ASC.People/ASC.People.csproj +++ b/products/ASC.People/ASC.People.csproj @@ -22,6 +22,11 @@ + + + + + diff --git a/web/ASC.Web.Api/Controllers/PeopleController.cs b/products/ASC.People/Controllers/PeopleController.cs similarity index 100% rename from web/ASC.Web.Api/Controllers/PeopleController.cs rename to products/ASC.People/Controllers/PeopleController.cs diff --git a/products/ASC.People/Controllers/SampleDataController.cs b/products/ASC.People/Controllers/SampleDataController.cs deleted file mode 100644 index fee675045a..0000000000 --- a/products/ASC.People/Controllers/SampleDataController.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; - -namespace ASC.People.Controllers -{ - [Route("api/[controller]")] - public class SampleDataController : Controller - { - private static string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - [HttpGet("[action]")] - public IEnumerable WeatherForecasts() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - DateFormatted = DateTime.Now.AddDays(index).ToString("d"), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }); - } - - public class WeatherForecast - { - public string DateFormatted { get; set; } - public int TemperatureC { get; set; } - public string Summary { get; set; } - - public int TemperatureF - { - get - { - return 32 + (int)(TemperatureC / 0.5556); - } - } - } - } -} diff --git a/web/ASC.Web.Api/Models/EmployeeWraper.cs b/products/ASC.People/Models/EmployeeWraper.cs similarity index 100% rename from web/ASC.Web.Api/Models/EmployeeWraper.cs rename to products/ASC.People/Models/EmployeeWraper.cs diff --git a/products/ASC.People/Program.cs b/products/ASC.People/Program.cs index c234c48586..98fe00e48c 100644 --- a/products/ASC.People/Program.cs +++ b/products/ASC.People/Program.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace ASC.People { diff --git a/products/ASC.People/appsettings.Development.json b/products/ASC.People/appsettings.Development.json deleted file mode 100644 index e203e9407e..0000000000 --- a/products/ASC.People/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - } -} diff --git a/products/ASC.People/appsettings.json b/products/ASC.People/appsettings.json deleted file mode 100644 index 8239cbea65..0000000000 --- a/products/ASC.People/appsettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Warning" - } - }, -"AllowedHosts": "*" -} diff --git a/web/ASC.Web.Api/ASC.Web.Api.csproj b/web/ASC.Web.Api/ASC.Web.Api.csproj index 08a0dea16f..0cf237c79a 100644 --- a/web/ASC.Web.Api/ASC.Web.Api.csproj +++ b/web/ASC.Web.Api/ASC.Web.Api.csproj @@ -6,16 +6,12 @@ - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 2da17e40cf..4389e58f4a 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -9,10 +9,14 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using System.Runtime.Loader; + using ASC.Common.Logging; using ASC.Web.Api.Handlers; using ASC.Web.Api.Middleware; - +using System.Linq; +using System.Reflection; +using System.IO; namespace ASC.Web.Api { @@ -35,13 +39,19 @@ namespace ASC.Web.Api services.AddAuthentication("cookie").AddScheme("cookie", a=> { }); - services.AddMvc(config => + var assemblies = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ASC*.dll").Select(Assembly.LoadFrom); + + var builder = services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); config.Filters.Add(new TypeFilterAttribute(typeof(FormatFilter))); config.Filters.Add(new AuthorizeFilter(policy)); }); + foreach (var a in assemblies) { + builder.AddApplicationPart(a); + } + services.AddLogManager(Configuration); } From bea25886b27726b9b203323d8452303d00581f1d Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Wed, 29 May 2019 18:19:36 +0300 Subject: [PATCH 4/4] Added CustomApiAttribute --- common/ASC.Api.Core/Core/CustomApiAttribute.cs | 9 +++++++++ products/ASC.People/ASC.People.csproj | 4 ++++ products/ASC.People/AssemblyInfo.cs | 4 ++++ web/ASC.Web.Api/Startup.cs | 10 ++++++---- 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 common/ASC.Api.Core/Core/CustomApiAttribute.cs create mode 100644 products/ASC.People/AssemblyInfo.cs diff --git a/common/ASC.Api.Core/Core/CustomApiAttribute.cs b/common/ASC.Api.Core/Core/CustomApiAttribute.cs new file mode 100644 index 0000000000..1e1b92ac4f --- /dev/null +++ b/common/ASC.Api.Core/Core/CustomApiAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace ASC.Api.Core +{ + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public class CustomApiAttribute : Attribute + { + } +} diff --git a/products/ASC.People/ASC.People.csproj b/products/ASC.People/ASC.People.csproj index 89d2f24819..fca372ba35 100644 --- a/products/ASC.People/ASC.People.csproj +++ b/products/ASC.People/ASC.People.csproj @@ -10,6 +10,10 @@ true + + false + + diff --git a/products/ASC.People/AssemblyInfo.cs b/products/ASC.People/AssemblyInfo.cs new file mode 100644 index 0000000000..235582bfd6 --- /dev/null +++ b/products/ASC.People/AssemblyInfo.cs @@ -0,0 +1,4 @@ + +using ASC.Api.Core; + +[assembly: CustomApi] diff --git a/web/ASC.Web.Api/Startup.cs b/web/ASC.Web.Api/Startup.cs index 4389e58f4a..0d548efcab 100644 --- a/web/ASC.Web.Api/Startup.cs +++ b/web/ASC.Web.Api/Startup.cs @@ -9,11 +9,11 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using System.Runtime.Loader; - +using ASC.Api.Core; using ASC.Common.Logging; using ASC.Web.Api.Handlers; using ASC.Web.Api.Middleware; + using System.Linq; using System.Reflection; using System.IO; @@ -39,8 +39,6 @@ namespace ASC.Web.Api services.AddAuthentication("cookie").AddScheme("cookie", a=> { }); - var assemblies = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ASC*.dll").Select(Assembly.LoadFrom); - var builder = services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); @@ -48,6 +46,10 @@ namespace ASC.Web.Api config.Filters.Add(new AuthorizeFilter(policy)); }); + var assemblies = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll") + .Select(Assembly.LoadFrom) + .Where(r => r.GetCustomAttribute() != null); + foreach (var a in assemblies) { builder.AddApplicationPart(a); }