From d7912798e84db55f66d269c0b5709e860c9d919b Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 08:54:49 +0300 Subject: [PATCH 01/23] Added Obsolete note --- .../AbpAuthorizationServiceCollectionExtensions.cs | 4 +++- .../Authorization/Permissions/AlwaysAllowPermissionChecker.cs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Authorization/Microsoft/Extensions/DependencyInjection/AbpAuthorizationServiceCollectionExtensions.cs b/framework/src/Volo.Abp.Authorization/Microsoft/Extensions/DependencyInjection/AbpAuthorizationServiceCollectionExtensions.cs index ff53ba7ae8..4294f572de 100644 --- a/framework/src/Volo.Abp.Authorization/Microsoft/Extensions/DependencyInjection/AbpAuthorizationServiceCollectionExtensions.cs +++ b/framework/src/Volo.Abp.Authorization/Microsoft/Extensions/DependencyInjection/AbpAuthorizationServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Authorization; +using System; +using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Authorization; using Volo.Abp.Authorization.Permissions; @@ -8,6 +9,7 @@ namespace Microsoft.Extensions.DependencyInjection public static class AbpAuthorizationServiceCollectionExtensions { //TODO: Remove this and use AddAlwaysAllowAuthorization + [Obsolete("Use AddAlwaysAllowAuthorization instead")] public static IServiceCollection AddAlwaysAllowPermissionChecker(this IServiceCollection services) { return services.Replace(ServiceDescriptor.Singleton()); diff --git a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/AlwaysAllowPermissionChecker.cs b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/AlwaysAllowPermissionChecker.cs index b5a75ce40e..77c8f4b665 100644 --- a/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/AlwaysAllowPermissionChecker.cs +++ b/framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/AlwaysAllowPermissionChecker.cs @@ -6,7 +6,7 @@ namespace Volo.Abp.Authorization.Permissions /// /// Always allows for any permission. /// - /// Use IServiceCollection.AddAlwaysAllowPermissionChecker() to replace + /// Use IServiceCollection.AddAlwaysAllowAuthorization() to replace /// IPermissionChecker with this class. This is useful for tests. /// public class AlwaysAllowPermissionChecker : IPermissionChecker From 5820c4e2c8f6f23ed732c48e7c900c9350b092bd Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 08:55:19 +0300 Subject: [PATCH 02/23] IdentityResourceDataSeeder should also add role identity resource. --- .../IdentityResources/IdentityResourceDataSeeder.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs index a5c1e23861..362fef9ae1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/IdentityResources/IdentityResourceDataSeeder.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources public IdentityResourceDataSeeder( IIdentityResourceRepository identityResourceRepository, - IGuidGenerator guidGenerator, + IGuidGenerator guidGenerator, IIdentityClaimTypeRepository claimTypeRepository) { IdentityResourceRepository = identityResourceRepository; @@ -23,13 +23,14 @@ namespace Volo.Abp.IdentityServer.IdentityResources public virtual async Task CreateStandardResourcesAsync() { - var resources = new IdentityServer4.Models.IdentityResource[] + var resources = new[] { new IdentityServer4.Models.IdentityResources.OpenId(), new IdentityServer4.Models.IdentityResources.Profile(), new IdentityServer4.Models.IdentityResources.Email(), new IdentityServer4.Models.IdentityResources.Address(), - new IdentityServer4.Models.IdentityResources.Phone() + new IdentityServer4.Models.IdentityResources.Phone(), + new IdentityServer4.Models.IdentityResource("role", "Roles of the user", new[] {"role"}) }; foreach (var resource in resources) @@ -42,7 +43,7 @@ namespace Volo.Abp.IdentityServer.IdentityResources await AddIdentityResourceIfNotExistsAsync(resource); } } - + protected virtual async Task AddIdentityResourceIfNotExistsAsync(IdentityServer4.Models.IdentityResource resource) { if (await IdentityResourceRepository.FindByNameAsync(resource.Name) != null) From 2bf8c5ba3d5291dcd1cb683617ac8e9a52a94254 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 10 Jan 2019 09:57:59 +0300 Subject: [PATCH 03/23] Identityserver apiscope fixes --- .../Volo/Abp/IdentityServer/ApiResources/ApiScope.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs index e81dd849ec..c54caea3a9 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/ApiResources/ApiScope.cs @@ -67,14 +67,14 @@ namespace Volo.Abp.IdentityServer.ApiResources UserClaims.Clear(); } - public virtual void RemoveClaim(string name, string type) + public virtual void RemoveClaim(string type) { - UserClaims.RemoveAll(r => r.Name == name && r.Type == type); + UserClaims.RemoveAll(r => r.Type == type); } - public virtual ApiScopeClaim FindClaim(string name, string type) + public virtual ApiScopeClaim FindClaim(string type) { - return UserClaims.FirstOrDefault(r => r.Name == name && r.Type == type); + return UserClaims.FirstOrDefault(r => r.Name == Name && r.Type == type); } public override object[] GetKeys() From ec6bef7780e6cc100c753e141a0e92b3ef700f32 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 10 Jan 2019 09:58:29 +0300 Subject: [PATCH 04/23] Identity server : added detailed apiresource for test --- .../IdentityServer/AbpIdentityServerTestDataBuilder.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index f3db9821b8..444eface65 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -57,7 +57,15 @@ namespace Volo.Abp.IdentityServer private void AddApiResources() { - _apiResourceRepository.Insert(new ApiResource(_testData.ApiResource1Id, "NewApiResource1")); + var apiResource = new ApiResource(_testData.ApiResource1Id, "NewApiResource1"); + apiResource.Description = nameof(apiResource.Description); + apiResource.DisplayName = nameof(apiResource.DisplayName); + + apiResource.AddScope(nameof(ApiScope.Name)); + apiResource.AddUserClaim(nameof(ApiResourceClaim.Type)); + apiResource.AddSecret(nameof(ApiSecret.Value)); + + _apiResourceRepository.Insert(apiResource); _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource2")); _apiResourceRepository.Insert(new ApiResource(_guidGenerator.Create(), "NewApiResource3")); } From fbc4428b2bc1fc4a6fa3291630925c28d07db6f8 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 10:11:10 +0300 Subject: [PATCH 05/23] Replace ApplicationConfigurationBuilder by AbpApplicationConfigurationAppService --- ... AbpApplicationConfigurationAppService.cs} | 20 ++++++++++--------- .../AbpApplicationConfigurationController.cs | 11 +++++----- ...pplicationConfigurationScriptController.cs | 8 ++++---- ...IAbpApplicationConfigurationAppService.cs} | 3 ++- .../ApplicationConfigurationBuilder_Tests.cs | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) rename framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/{ApplicationConfigurationBuilder.cs => AbpApplicationConfigurationAppService.cs} (87%) rename framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/{IApplicationConfigurationBuilder.cs => IAbpApplicationConfigurationAppService.cs} (57%) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs similarity index 87% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 9ad4d2343e..17c1d78911 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -1,24 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Services; using Volo.Abp.Authorization; -using Volo.Abp.DependencyInjection; using Volo.Abp.Localization; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { - public class ApplicationConfigurationBuilder : IApplicationConfigurationBuilder, ITransientDependency + public class AbpApplicationConfigurationAppService : ApplicationService, IAbpApplicationConfigurationAppService { private readonly AbpLocalizationOptions _localizationOptions; private readonly IServiceProvider _serviceProvider; private readonly IAbpAuthorizationPolicyProvider _abpAuthorizationPolicyProvider; private readonly IAuthorizationService _authorizationService; - public ApplicationConfigurationBuilder( + public AbpApplicationConfigurationAppService( IOptions localizationOptions, IServiceProvider serviceProvider, IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider, @@ -30,7 +30,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations _localizationOptions = localizationOptions.Value; } - public async Task GetAsync() //TODO: Test, at least with a simple Get + public async Task GetAsync() { //TODO: Optimize & cache..? @@ -66,7 +66,9 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { var dictionary = new Dictionary(); - var localizer = _serviceProvider.GetRequiredService(typeof(IStringLocalizer<>).MakeGenericType(resource.ResourceType)) as IStringLocalizer; + var localizer = _serviceProvider.GetRequiredService( + typeof(IStringLocalizer<>).MakeGenericType(resource.ResourceType) + ) as IStringLocalizer; foreach (var localizedString in localizer.GetAllStrings()) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs index b117a68956..98e6d41b8e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs @@ -6,17 +6,18 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations [Route("api/abp/application-configuration")] public class AbpApplicationConfigurationController : AbpController { - private readonly IApplicationConfigurationBuilder _configurationBuilder; + private readonly IAbpApplicationConfigurationAppService _applicationConfigurationAppService; - public AbpApplicationConfigurationController(IApplicationConfigurationBuilder configurationBuilder) + public AbpApplicationConfigurationController( + IAbpApplicationConfigurationAppService applicationConfigurationAppService) { - _configurationBuilder = configurationBuilder; + _applicationConfigurationAppService = applicationConfigurationAppService; } [HttpGet] - public Task Get() + public Task GetAsync() { - return _configurationBuilder.GetAsync(); + return _applicationConfigurationAppService.GetAsync(); } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs index 5772eceeb0..291cc3b1bf 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationScriptController.cs @@ -12,14 +12,14 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations [DisableAuditing] public class AbpApplicationConfigurationScriptController : AbpController { - private readonly IApplicationConfigurationBuilder _configurationBuilder; + private readonly IAbpApplicationConfigurationAppService _configurationAppService; private readonly IJsonSerializer _jsonSerializer; public AbpApplicationConfigurationScriptController( - IApplicationConfigurationBuilder configurationBuilder, + IAbpApplicationConfigurationAppService configurationAppService, IJsonSerializer jsonSerializer) { - _configurationBuilder = configurationBuilder; + _configurationAppService = configurationAppService; _jsonSerializer = jsonSerializer; } @@ -28,7 +28,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations public async Task Get() { return CreateAbpExtendScript( - await _configurationBuilder.GetAsync() + await _configurationAppService.GetAsync() ); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationBuilder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs similarity index 57% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationBuilder.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs index 2b820f48c6..4c521b9efc 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IApplicationConfigurationBuilder.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs @@ -1,8 +1,9 @@ using System.Threading.Tasks; +using Volo.Abp.Application.Services; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { - public interface IApplicationConfigurationBuilder + public interface IAbpApplicationConfigurationAppService : IApplicationService { Task GetAsync(); } diff --git a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs index 0d2e84a0cf..c5f53e4721 100644 --- a/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs +++ b/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationBuilder_Tests.cs @@ -9,7 +9,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations [Fact] public async Task ApplicationConfigurationBuilder_GetAsync() { - var applicationConfigurationBuilder = GetRequiredService(); + var applicationConfigurationBuilder = GetRequiredService(); var config = await applicationConfigurationBuilder.GetAsync(); From 71b269ef94e941cb11770af7a1569efb2fa657e7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 10 Jan 2019 10:21:25 +0300 Subject: [PATCH 06/23] Identity server : added detailed identityResource for test --- .../IdentityServer/AbpIdentityServerTestDataBuilder.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs index 444eface65..42f76d44a0 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestDataBuilder.cs @@ -50,7 +50,15 @@ namespace Volo.Abp.IdentityServer private void AddIdentityResources() { - _identityResourceRepository.Insert(new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1")); + var identityResource = new IdentityResource(_testData.IdentityResource1Id, "NewIdentityResource1") + { + Description = nameof(Client.Description), + DisplayName = nameof(IdentityResource.DisplayName) + }; + + identityResource.AddUserClaim(nameof(ApiResourceClaim.Type)); + + _identityResourceRepository.Insert(identityResource); _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource2")); _identityResourceRepository.Insert(new IdentityResource(_guidGenerator.Create(), "NewIdentityResource3")); } From bb2b87165f5a30fcdf92cf4ebeacbed1e8921f10 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 11:29:17 +0300 Subject: [PATCH 07/23] Resolved #726: Introduce IHttpClientProxy and explicit usage of client proxies. --- .../AspNetCore/Dynamic-CSharp-API-Clients.md | 96 ++++++++------- ...lectionDynamicHttpClientProxyExtensions.cs | 114 +++++++++++++++--- .../Client/DynamicProxying/HttpClientProxy.cs | 12 ++ .../DynamicProxying/IHttpClientProxy.cs | 7 ++ 4 files changed, 173 insertions(+), 56 deletions(-) create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpClientProxy.cs create mode 100644 framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IHttpClientProxy.cs diff --git a/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md b/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md index eee2abacc0..a96526318f 100644 --- a/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md +++ b/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md @@ -7,13 +7,13 @@ ABP can dynamically create C# API client proxies to call remote HTTP services (R Your service/controller should implement an interface that is shared between the server and the client. So, first define a service interface in a shared library project. Example: ````csharp -public interface IBookService : IApplicationService +public interface IBookAppService : IApplicationService { Task> GetListAsync(); } ```` -Your interface should implement the `IRemoteService` interface. Since the `IApplicationService` inherits the `IRemoteService` interface, the `IBookService` above satisfies this condition. +Your interface should implement the `IRemoteService` interface to be automatically discovered. Since the `IApplicationService` inherits the `IRemoteService` interface, the `IBookAppService` above satisfies this condition. Implement this class in your service application. You can use [auto API controller system](Auto-API-Controllers.md) to expose the service as a REST API endpoint. @@ -45,13 +45,6 @@ public class MyClientAppModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { - //Configure remote end point - context.Services.Configure(options => - { - options.RemoteServices.Default = - new RemoteServiceConfiguration("http://localhost:53929/"); - }); - //Create dynamic client proxies context.Services.AddHttpClientProxies( typeof(BookStoreApplicationModule).Assembly @@ -60,10 +53,24 @@ public class MyClientAppModule : AbpModule } ```` -`RemoteServiceOptions` is used to configure endpoints for remote services (This example sets the default endpoint while you can have different service endpoints used by different clients. See the "Multiple Remote Service Endpoint" section). - `AddHttpClientProxies` method gets an assembly, finds all service interfaces in the given assembly, creates and registers proxy classes. +### Endpoint Configuration + +`RemoteServices` section in the `appsettings.json` file is used to get remote service address by default. Simplest configuration is shown below: + +```` +{ + "RemoteServices": { + "Default": { + "BaseUrl": "http://localhost:53929/" + } + } +} +```` + +See the "RemoteServiceOptions" section below for more detailed configuration. + ## Usage It's straightforward to use. Just inject the service interface in the client application code: @@ -71,9 +78,9 @@ It's straightforward to use. Just inject the service interface in the client app ````csharp public class MyService : ITransientDependency { - private readonly IBookService _bookService; + private readonly IBookAppService _bookService; - public MyService(IBookService bookService) + public MyService(IBookAppService bookService) { _bookService = bookService; } @@ -89,40 +96,34 @@ public class MyService : ITransientDependency } ```` -This sample injects the `IBookService` service interface defined above. The dynamic client proxy implementation makes an HTTP call whenever a service method is called by the client. +This sample injects the `IBookAppService` service interface defined above. The dynamic client proxy implementation makes an HTTP call whenever a service method is called by the client. -## Configuration Details +### IHttpClientProxy Interface -### RemoteServiceOptions +While you can inject `IBookAppService` like above to use the client proxy, you could inject `IHttpClientProxy` for a more explicit usage. In this case you will use the `Service` property of the `IHttpClientProxy` interface. -While you can configure `RemoteServiceOptions` as the example shown above, you can let it to read from your `appsettings.json` file. Add a `RemoteServices` section to your `appsettings.json` file: +## Configuration -````json -{ - "RemoteServices": { - "Default": { - "BaseUrl": "http://localhost:53929/" - } - } -} -```` +### RemoteServiceOptions -Then you can pass your `IConfigurationRoot` instance directly to the `Configure()` method as shown below: +`RemoteServiceOptions` is automatically set from the `appsettings.json` by default. Alternatively, you can use `Configure` method to set or override it. Example: ````csharp -var configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - -context.Services.Configure(configuration); +public override void ConfigureServices(ServiceConfigurationContext context) +{ + context.Services.Configure(options => + { + options.RemoteServices.Default = + new RemoteServiceConfiguration("http://localhost:53929/"); + }); + + //... +} ```` -This approach is useful since it's easy to change the configuration later without touching to the code. +### Multiple Remote Service Endpoints -#### Multiple Remote Service Endpoint - -The examples above have configured the "Default" remote service endpoint. You may have different endpoints for different services (as like in a microservice approach where each microservice has different endpoint). In this case, you can add other endpoints to your configuration file: +The examples above have configured the "Default" remote service endpoint. You may have different endpoints for different services (as like in a microservice approach where each microservice has different endpoints). In this case, you can add other endpoints to your configuration file: ````json { @@ -137,10 +138,6 @@ The examples above have configured the "Default" remote service endpoint. You ma } ```` -See the next section to learn how to use this new endpoint. - -### AddHttpClientProxies Method - `AddHttpClientProxies` method can get an additional parameter for the remote service name. Example: ````csharp @@ -150,4 +147,19 @@ context.Services.AddHttpClientProxies( ); ```` -`remoteServiceName` parameter matches the service endpoint configured via `RemoteServiceOptions`. If the `BookStore` endpoint is not defined then it fallbacks to the `Default` endpoint. \ No newline at end of file +`remoteServiceName` parameter matches the service endpoint configured via `RemoteServiceOptions`. If the `BookStore` endpoint is not defined then it fallbacks to the `Default` endpoint. + +### As Default Services + +When you create a service proxy for `IBookAppService`, you can directly inject the `IBookAppService` to use the proxy client (as shown in the usage section). You can pass `asDefaultServices: false` to the `AddHttpClientProxies` method to disable this feature. + +````csharp +context.Services.AddHttpClientProxies( + typeof(BookStoreApplicationModule).Assembly, + asDefaultServices: false +); +```` + +If you disable `asDefaultServices`, you can only use `IHttpClientProxy` interface to use the client proxies (see the related section above). + +Using `asDefaultServices: false` may only be needed if your application has multiple implementation of the service, so you want to distinguish the HTTP client proxy and do not want to override the other implementation. \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs index cb120b1315..40e2f11b73 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs +++ b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Reflection; using Castle.DynamicProxy; +using JetBrains.Annotations; using Volo.Abp; using Volo.Abp.Castle.DynamicProxy; using Volo.Abp.Http.Client; @@ -13,8 +14,28 @@ namespace Microsoft.Extensions.DependencyInjection { private static readonly ProxyGenerator ProxyGeneratorInstance = new ProxyGenerator(); - public static IServiceCollection AddHttpClientProxies(this IServiceCollection services, Assembly assembly, string remoteServiceName = RemoteServiceConfigurationDictionary.DefaultName) + /// + /// Registers HTTP Client Proxies for all public interfaces + /// extend the interface in the + /// given . + /// + /// Service collection + /// The assembly containing the service interfaces + /// + /// The name of the remote service configuration to be used by the HTTP Client proxies. + /// See . + /// + /// + /// True, to register the HTTP client proxy as the default implementation for the services. + /// + public static IServiceCollection AddHttpClientProxies( + [NotNull] this IServiceCollection services, + [NotNull] Assembly assembly, + [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, + bool asDefaultService = true) { + Check.NotNull(services, nameof(assembly)); + //TODO: Make a configuration option and add remoteServiceName inside it! //TODO: Add option to change type filter @@ -24,36 +45,101 @@ namespace Microsoft.Extensions.DependencyInjection foreach (var serviceType in serviceTypes) { - services.AddHttpClientProxy(serviceType, remoteServiceName); + services.AddHttpClientProxy( + serviceType, + remoteServiceConfigurationName, + asDefaultService + ); } return services; } - public static IServiceCollection AddHttpClientProxy(this IServiceCollection services, string remoteServiceName = RemoteServiceConfigurationDictionary.DefaultName) + /// + /// Registers HTTP Client Proxy for given service type . + /// + /// Type of the service + /// Service collection + /// + /// The name of the remote service configuration to be used by the HTTP Client proxy. + /// See . + /// + /// + /// True, to register the HTTP client proxy as the default implementation for the service . + /// + public static IServiceCollection AddHttpClientProxy( + [NotNull] this IServiceCollection services, + [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, + bool asDefaultService = true) { - return services.AddHttpClientProxy(typeof(T), remoteServiceName); + return services.AddHttpClientProxy( + typeof(T), + remoteServiceConfigurationName, + asDefaultService + ); } - public static IServiceCollection AddHttpClientProxy(this IServiceCollection services, Type type, string remoteServiceName = RemoteServiceConfigurationDictionary.DefaultName) + /// + /// Registers HTTP Client Proxy for given service . + /// + /// Service collection + /// Type of the service + /// + /// The name of the remote service configuration to be used by the HTTP Client proxy. + /// See . + /// + /// + /// True, to register the HTTP client proxy as the default implementation for the service . + /// + public static IServiceCollection AddHttpClientProxy( + [NotNull] this IServiceCollection services, + [NotNull] Type type, + [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, + bool asDefaultService = true) { + Check.NotNull(services, nameof(services)); + Check.NotNull(type, nameof(type)); + Check.NotNull(remoteServiceConfigurationName, nameof(remoteServiceConfigurationName)); + services.Configure(options => { - options.HttpClientProxies[type] = new DynamicHttpClientProxyConfig(type, remoteServiceName); + options.HttpClientProxies[type] = new DynamicHttpClientProxyConfig(type, remoteServiceConfigurationName); }); var interceptorType = typeof(DynamicHttpProxyInterceptor<>).MakeGenericType(type); services.AddTransient(interceptorType); var interceptorAdapterType = typeof(CastleAbpInterceptorAdapter<>).MakeGenericType(interceptorType); - return services.AddTransient( - type, - serviceProvider => ProxyGeneratorInstance - .CreateInterfaceProxyWithoutTarget( - type, - (IInterceptor) serviceProvider.GetRequiredService(interceptorAdapterType) - ) - ); + + if (asDefaultService) + { + services.AddTransient( + type, + serviceProvider => ProxyGeneratorInstance + .CreateInterfaceProxyWithoutTarget( + type, + (IInterceptor)serviceProvider.GetRequiredService(interceptorAdapterType) + ) + ); + } + + services.AddTransient( + typeof(IHttpClientProxy<>).MakeGenericType(type), + serviceProvider => + { + var service = ProxyGeneratorInstance + .CreateInterfaceProxyWithoutTarget( + type, + (IInterceptor) serviceProvider.GetRequiredService(interceptorAdapterType) + ); + + return Activator.CreateInstance( + typeof(HttpClientProxy<>).MakeGenericType(type), + service + ); + }); + + return services; } } } diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpClientProxy.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpClientProxy.cs new file mode 100644 index 0000000000..6afa2e6dee --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/HttpClientProxy.cs @@ -0,0 +1,12 @@ +namespace Volo.Abp.Http.Client.DynamicProxying +{ + public class HttpClientProxy : IHttpClientProxy + { + public TRemoteService Service { get; } + + public HttpClientProxy(TRemoteService service) + { + Service = service; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IHttpClientProxy.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IHttpClientProxy.cs new file mode 100644 index 0000000000..3b962f523d --- /dev/null +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/DynamicProxying/IHttpClientProxy.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Http.Client.DynamicProxying +{ + public interface IHttpClientProxy + { + TRemoteService Service { get; } + } +} From f9521f48a8c080aee802ac1a557a23c29b5c2720 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 11:31:49 +0300 Subject: [PATCH 08/23] Update Dynamic-CSharp-API-Clients.md --- docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md b/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md index a96526318f..0b0667dd0d 100644 --- a/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md +++ b/docs/en/AspNetCore/Dynamic-CSharp-API-Clients.md @@ -160,6 +160,6 @@ context.Services.AddHttpClientProxies( ); ```` -If you disable `asDefaultServices`, you can only use `IHttpClientProxy` interface to use the client proxies (see the related section above). +Using `asDefaultServices: false` may only be needed if your application has already an implementation of the service and you do not want to override/replace the other implementation by your client proxy. -Using `asDefaultServices: false` may only be needed if your application has multiple implementation of the service, so you want to distinguish the HTTP client proxy and do not want to override the other implementation. \ No newline at end of file +> If you disable `asDefaultServices`, you can only use `IHttpClientProxy` interface to use the client proxies (see the related section above). \ No newline at end of file From 9b70291d5cd35840fd1fdee9c900eab664edf1ce Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 11:33:01 +0300 Subject: [PATCH 09/23] Rename asDefaultService to asDefaultServices --- .../ServiceCollectionDynamicHttpClientProxyExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs index 40e2f11b73..f145132633 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs +++ b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs @@ -25,14 +25,14 @@ namespace Microsoft.Extensions.DependencyInjection /// The name of the remote service configuration to be used by the HTTP Client proxies. /// See . /// - /// + /// /// True, to register the HTTP client proxy as the default implementation for the services. /// public static IServiceCollection AddHttpClientProxies( [NotNull] this IServiceCollection services, [NotNull] Assembly assembly, [NotNull] string remoteServiceConfigurationName = RemoteServiceConfigurationDictionary.DefaultName, - bool asDefaultService = true) + bool asDefaultServices = true) { Check.NotNull(services, nameof(assembly)); @@ -48,7 +48,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddHttpClientProxy( serviceType, remoteServiceConfigurationName, - asDefaultService + asDefaultServices ); } From dbf0ed1703353802a19d462ea2b91293c9e21bd4 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 11:48:37 +0300 Subject: [PATCH 10/23] Added empty Volo.Abp.AspNetCore.Mvc.Client package --- framework/Volo.Abp.sln | 9 ++++++++- .../Volo.Abp.AspNetCore.Mvc.Client.csproj | 20 +++++++++++++++++++ .../Client/AbpAspNetCoreMvcClientModule.cs | 13 ++++++++++++ .../AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 2 -- nupkg/common.ps1 | 1 + 5 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 3b18df4e23..fb1dbb8063 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -220,7 +220,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Settings.Tests", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Http.Client.IdentityModel", "src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj", "{D211A446-38FA-4F97-9A95-1F004A0FFF69}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.IdentityModel", "src\Volo.Abp.IdentityModel\Volo.Abp.IdentityModel.csproj", "{64D99E19-EE25-465A-82E5-17B25F4C4E18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityModel", "src\Volo.Abp.IdentityModel\Volo.Abp.IdentityModel.csproj", "{64D99E19-EE25-465A-82E5-17B25F4C4E18}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Client", "src\Volo.Abp.AspNetCore.Mvc.Client\Volo.Abp.AspNetCore.Mvc.Client.csproj", "{E803DDB8-81EA-454B-9A66-9C2941100B67}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -628,6 +630,10 @@ Global {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Debug|Any CPU.Build.0 = Debug|Any CPU {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Release|Any CPU.ActiveCfg = Release|Any CPU {64D99E19-EE25-465A-82E5-17B25F4C4E18}.Release|Any CPU.Build.0 = Release|Any CPU + {E803DDB8-81EA-454B-9A66-9C2941100B67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E803DDB8-81EA-454B-9A66-9C2941100B67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E803DDB8-81EA-454B-9A66-9C2941100B67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E803DDB8-81EA-454B-9A66-9C2941100B67}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -735,6 +741,7 @@ Global {5F3A2D1E-EA89-40A7-8D2F-FB4EB2092403} = {447C8A77-E5F0-4538-8687-7383196D04EA} {D211A446-38FA-4F97-9A95-1F004A0FFF69} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {64D99E19-EE25-465A-82E5-17B25F4C4E18} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {E803DDB8-81EA-454B-9A66-9C2941100B67} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj new file mode 100644 index 0000000000..438b6663dc --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + Volo.Abp.AspNetCore.Mvc.Client + Volo.Abp.AspNetCore.Mvc.Client + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs new file mode 100644 index 0000000000..da4eab7848 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs @@ -0,0 +1,13 @@ +using Volo.Abp.Http.Client; +using Volo.Abp.Modularity; + +namespace Volo.Abp.AspNetCore.Mvc.Client +{ + [DependsOn( + typeof(AbpHttpClientModule) + )] + public class AbpAspNetCoreMvcClientModule : AbpModule + { + + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index cac53d4611..d28f5bb8c8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.DependencyInjection; @@ -21,7 +20,6 @@ using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.VirtualFileSystem; -using Volo.Abp.Http; using Volo.Abp.Http.Modeling; using Volo.Abp.Localization; using Volo.Abp.UI; diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index e29ba634b9..2ef7e66c9d 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -28,6 +28,7 @@ $projects = ( "framework/src/Volo.Abp.AspNetCore.Authentication.OAuth", "framework/src/Volo.Abp.AspNetCore.MultiTenancy", "framework/src/Volo.Abp.AspNetCore.Mvc", + "framework/src/Volo.Abp.AspNetCore.Mvc.Client", "framework/src/Volo.Abp.AspNetCore.Mvc.UI", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling", From f1ec845038c26671995d070c6c327539d2af152b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 10 Jan 2019 11:49:40 +0300 Subject: [PATCH 11/23] Resolved #724 Replace AddAlwaysAllowPermissionChecker usage by AddAlwaysAllowAuthorization --- .../Volo/Abp/Identity/AbpIdentityTestBaseModule.cs | 2 +- .../Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs | 2 +- .../AbpTenantManagementApplicationTestModule.cs | 2 +- .../MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs | 2 +- .../MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestBaseModule.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestBaseModule.cs index 55eed7374a..4f33976649 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestBaseModule.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestBaseModule.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.Identity { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddAlwaysAllowPermissionChecker(); + context.Services.AddAlwaysAllowAuthorization(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs index b5617e489f..d823634160 100644 --- a/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs +++ b/modules/identityserver/test/Volo.Abp.IdentityServer.TestBase/Volo/Abp/IdentityServer/AbpIdentityServerTestBaseModule.cs @@ -14,7 +14,7 @@ namespace Volo.Abp.IdentityServer { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddAlwaysAllowPermissionChecker(); + context.Services.AddAlwaysAllowAuthorization(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/modules/tenant-management/test/Volo.Abp.TenantManagement.Application.Tests/Volo/Abp/TenantManagement/AbpTenantManagementApplicationTestModule.cs b/modules/tenant-management/test/Volo.Abp.TenantManagement.Application.Tests/Volo/Abp/TenantManagement/AbpTenantManagementApplicationTestModule.cs index e5417381dc..f15708fd42 100644 --- a/modules/tenant-management/test/Volo.Abp.TenantManagement.Application.Tests/Volo/Abp/TenantManagement/AbpTenantManagementApplicationTestModule.cs +++ b/modules/tenant-management/test/Volo.Abp.TenantManagement.Application.Tests/Volo/Abp/TenantManagement/AbpTenantManagementApplicationTestModule.cs @@ -11,7 +11,7 @@ namespace Volo.Abp.TenantManagement { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddAlwaysAllowPermissionChecker(); + context.Services.AddAlwaysAllowAuthorization(); } } } diff --git a/templates/module/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs b/templates/module/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs index e3e078f09a..3e03927dee 100644 --- a/templates/module/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs +++ b/templates/module/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs @@ -16,7 +16,7 @@ namespace MyCompanyName.MyProjectName { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddAlwaysAllowPermissionChecker(); + context.Services.AddAlwaysAllowAuthorization(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) diff --git a/templates/service/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs b/templates/service/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs index e3e078f09a..3e03927dee 100644 --- a/templates/service/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs +++ b/templates/service/test/MyCompanyName.MyProjectName.TestBase/MyCompanyName/MyProjectName/MyProjectNameTestBaseModule.cs @@ -16,7 +16,7 @@ namespace MyCompanyName.MyProjectName { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddAlwaysAllowPermissionChecker(); + context.Services.AddAlwaysAllowAuthorization(); } public override void OnApplicationInitialization(ApplicationInitializationContext context) From a32b1d23fc97bd8b50a4206195dcd9953062f5e4 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 11:56:16 +0300 Subject: [PATCH 12/23] Created empty Volo.Abp.AspNetCore.Mvc.Contracts package. --- framework/Volo.Abp.sln | 7 +++++++ .../Volo.Abp.AspNetCore.Mvc.Client.csproj | 1 + .../Client/AbpAspNetCoreMvcClientModule.cs | 3 ++- .../Volo.Abp.AspNetCore.Mvc.Contracts.csproj | 20 +++++++++++++++++++ .../Mvc/AbpAspNetCoreMvcContractsModule.cs | 9 +++++++++ nupkg/common.ps1 | 3 ++- 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index fb1dbb8063..08104ef769 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -224,6 +224,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.IdentityModel", "s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Client", "src\Volo.Abp.AspNetCore.Mvc.Client\Volo.Abp.AspNetCore.Mvc.Client.csproj", "{E803DDB8-81EA-454B-9A66-9C2941100B67}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Mvc.Contracts", "src\Volo.Abp.AspNetCore.Mvc.Contracts\Volo.Abp.AspNetCore.Mvc.Contracts.csproj", "{88F6D091-CA16-4B71-9499-8D5B8FA2E712}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -634,6 +636,10 @@ Global {E803DDB8-81EA-454B-9A66-9C2941100B67}.Debug|Any CPU.Build.0 = Debug|Any CPU {E803DDB8-81EA-454B-9A66-9C2941100B67}.Release|Any CPU.ActiveCfg = Release|Any CPU {E803DDB8-81EA-454B-9A66-9C2941100B67}.Release|Any CPU.Build.0 = Release|Any CPU + {88F6D091-CA16-4B71-9499-8D5B8FA2E712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88F6D091-CA16-4B71-9499-8D5B8FA2E712}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88F6D091-CA16-4B71-9499-8D5B8FA2E712}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88F6D091-CA16-4B71-9499-8D5B8FA2E712}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -742,6 +748,7 @@ Global {D211A446-38FA-4F97-9A95-1F004A0FFF69} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {64D99E19-EE25-465A-82E5-17B25F4C4E18} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {E803DDB8-81EA-454B-9A66-9C2941100B67} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {88F6D091-CA16-4B71-9499-8D5B8FA2E712} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj index 438b6663dc..f748234d45 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj @@ -14,6 +14,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs index da4eab7848..edd2e66411 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs @@ -4,7 +4,8 @@ using Volo.Abp.Modularity; namespace Volo.Abp.AspNetCore.Mvc.Client { [DependsOn( - typeof(AbpHttpClientModule) + typeof(AbpHttpClientModule), + typeof(AbpAspNetCoreMvcContractsModule) )] public class AbpAspNetCoreMvcClientModule : AbpModule { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj new file mode 100644 index 0000000000..9413ad750f --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + Volo.Abp.AspNetCore.Mvc.Contracts + Volo.Abp.AspNetCore.Mvc.Contracts + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs new file mode 100644 index 0000000000..6415a6fbe9 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.AspNetCore.Mvc +{ + public class AbpAspNetCoreMvcContractsModule : AbpModule + { + + } +} diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 2ef7e66c9d..83f5e84075 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -28,7 +28,8 @@ $projects = ( "framework/src/Volo.Abp.AspNetCore.Authentication.OAuth", "framework/src/Volo.Abp.AspNetCore.MultiTenancy", "framework/src/Volo.Abp.AspNetCore.Mvc", - "framework/src/Volo.Abp.AspNetCore.Mvc.Client", + "framework/src/Volo.Abp.AspNetCore.Mvc.Contracts", + "framework/src/Volo.Abp.AspNetCore.Mvc.Client", "framework/src/Volo.Abp.AspNetCore.Mvc.UI", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap", "framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling", From e76217fabda1504b97a5ed2a2722f22cdf35fec6 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 10 Jan 2019 14:31:00 +0300 Subject: [PATCH 13/23] Moved contracts to Volo.Abp.AspNetCore.Mvc.Contracts module --- .../Mvc/Client/AbpAspNetCoreMvcClientModule.cs | 12 +++++++++++- .../Volo.Abp.AspNetCore.Mvc.Contracts.csproj | 2 +- .../Mvc/AbpAspNetCoreMvcContractsModule.cs | 6 +++++- .../ApplicationAuthConfigurationDto.cs | 0 .../ApplicationConfigurationDto.cs | 0 .../ApplicationLocalizationConfigurationDto.cs | 0 .../IAbpApplicationConfigurationAppService.cs | 0 .../Volo.Abp.AspNetCore.Mvc.csproj | 2 +- .../Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs | 13 +++++++------ ...iceCollectionDynamicHttpClientProxyExtensions.cs | 2 +- 10 files changed, 26 insertions(+), 11 deletions(-) rename framework/src/{Volo.Abp.AspNetCore.Mvc => Volo.Abp.AspNetCore.Mvc.Contracts}/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs (100%) rename framework/src/{Volo.Abp.AspNetCore.Mvc => Volo.Abp.AspNetCore.Mvc.Contracts}/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs (100%) rename framework/src/{Volo.Abp.AspNetCore.Mvc => Volo.Abp.AspNetCore.Mvc.Contracts}/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs (100%) rename framework/src/{Volo.Abp.AspNetCore.Mvc => Volo.Abp.AspNetCore.Mvc.Contracts}/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs (100%) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs index edd2e66411..0d33a58921 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs @@ -1,4 +1,5 @@ -using Volo.Abp.Http.Client; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Http.Client; using Volo.Abp.Modularity; namespace Volo.Abp.AspNetCore.Mvc.Client @@ -9,6 +10,15 @@ namespace Volo.Abp.AspNetCore.Mvc.Client )] public class AbpAspNetCoreMvcClientModule : AbpModule { + public const string RemoteServiceName = "AbpMvcClient"; + public override void ConfigureServices(ServiceConfigurationContext context) + { + context.Services.AddHttpClientProxies( + typeof(AbpAspNetCoreMvcContractsModule).Assembly, + RemoteServiceName, + asDefaultServices: false + ); + } } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj index 9413ad750f..8141097dc6 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo.Abp.AspNetCore.Mvc.Contracts.csproj @@ -14,7 +14,7 @@ - + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs index 6415a6fbe9..54a7589dd4 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcContractsModule.cs @@ -1,7 +1,11 @@ -using Volo.Abp.Modularity; +using Volo.Abp.Application; +using Volo.Abp.Modularity; namespace Volo.Abp.AspNetCore.Mvc { + [DependsOn( + typeof(AbpDddApplicationModule) + )] public class AbpAspNetCoreMvcContractsModule : AbpModule { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs similarity index 100% rename from framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs rename to framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/IAbpApplicationConfigurationAppService.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj index 6083bee6ba..e99572852e 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo.Abp.AspNetCore.Mvc.csproj @@ -15,8 +15,8 @@ + - diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index d28f5bb8c8..a1c637797a 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -15,7 +15,6 @@ using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.ViewComponents; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.ApiVersioning; -using Volo.Abp.Application; using Volo.Abp.AspNetCore.Mvc.Conventions; using Volo.Abp.AspNetCore.Mvc.DependencyInjection; using Volo.Abp.AspNetCore.Mvc.Localization; @@ -26,11 +25,13 @@ using Volo.Abp.UI; namespace Volo.Abp.AspNetCore.Mvc { - [DependsOn(typeof(AbpAspNetCoreModule))] - [DependsOn(typeof(AbpLocalizationModule))] - [DependsOn(typeof(AbpApiVersioningAbstractionsModule))] - [DependsOn(typeof(AbpDddApplicationModule))] - [DependsOn(typeof(AbpUiModule))] + [DependsOn( + typeof(AbpAspNetCoreModule), + typeof(AbpLocalizationModule), + typeof(AbpApiVersioningAbstractionsModule), + typeof(AbpAspNetCoreMvcContractsModule), + typeof(AbpUiModule) + )] public class AbpAspNetCoreMvcModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) diff --git a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs index f145132633..7689e94494 100644 --- a/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs +++ b/framework/src/Volo.Abp.Http.Client/Microsoft/Extensions/DependencyInjection/ServiceCollectionDynamicHttpClientProxyExtensions.cs @@ -99,7 +99,7 @@ namespace Microsoft.Extensions.DependencyInjection { Check.NotNull(services, nameof(services)); Check.NotNull(type, nameof(type)); - Check.NotNull(remoteServiceConfigurationName, nameof(remoteServiceConfigurationName)); + Check.NotNullOrWhiteSpace(remoteServiceConfigurationName, nameof(remoteServiceConfigurationName)); services.Configure(options => { From 48a831027358c31e2a4a1d62ede74b3ce5d4bc97 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 10 Jan 2019 15:29:45 +0300 Subject: [PATCH 14/23] Update IdentityServerDataSeeder.cs --- .../host/IdentityServerHost/IdentityServerDataSeeder.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/templates/service/host/IdentityServerHost/IdentityServerDataSeeder.cs b/templates/service/host/IdentityServerHost/IdentityServerDataSeeder.cs index 5820027c8e..054a895594 100644 --- a/templates/service/host/IdentityServerHost/IdentityServerDataSeeder.cs +++ b/templates/service/host/IdentityServerHost/IdentityServerDataSeeder.cs @@ -79,11 +79,8 @@ namespace IdentityServerHost client.AddScope("roles"); client.AddScope("unique_name"); - client.AddGrantTypes(new List - { - "client_credentials", - "password" - }); + client.AddGrantType("client_credentials"); + client.AddGrantType("password"); client.AddSecret("K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols="); From a523e8cc4c756052dd7e082ba1ea03131fea3222 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Fri, 11 Jan 2019 09:04:47 +0300 Subject: [PATCH 15/23] Implemented AbpAspNetCoreMvcClientModule --- .../Volo.Abp.AspNetCore.Mvc.Client.csproj | 1 + .../Client/AbpAspNetCoreMvcClientModule.cs | 4 +- .../CachedApplicationConfigurationClient.cs | 65 +++++++++++++++++++ .../ICachedApplicationConfigurationClient.cs | 10 +++ .../Mvc/Client/RemotePermissionChecker.cs | 32 +++++++++ .../ApplicationAuthConfigurationDto.cs | 4 +- .../ApplicationConfigurationDto.cs | 7 +- ...ApplicationLocalizationConfigurationDto.cs | 4 +- .../CurrentUserDto.cs | 16 +++++ .../AbpApplicationConfigurationAppService.cs | 20 +++++- .../AbpApplicationConfigurationController.cs | 2 +- .../AspNetCoreApiDescriptionModelProvider.cs | 1 + ...delRemoteServiceHttpClientAuthenticator.cs | 6 +- 13 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/CurrentUserDto.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj index f748234d45..911782697b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo.Abp.AspNetCore.Mvc.Client.csproj @@ -15,6 +15,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs index 0d33a58921..3f1ed47435 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Caching; using Volo.Abp.Http.Client; using Volo.Abp.Modularity; @@ -6,7 +7,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Client { [DependsOn( typeof(AbpHttpClientModule), - typeof(AbpAspNetCoreMvcContractsModule) + typeof(AbpAspNetCoreMvcContractsModule), + typeof(AbpCachingModule) )] public class AbpAspNetCoreMvcClientModule : AbpModule { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs new file mode 100644 index 0000000000..60338e6546 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/CachedApplicationConfigurationClient.cs @@ -0,0 +1,65 @@ +using System; +using Microsoft.AspNetCore.Http; +using System.Threading.Tasks; +using Microsoft.Extensions.Caching.Distributed; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.DynamicProxying; +using Volo.Abp.Users; + +namespace Volo.Abp.AspNetCore.Mvc.Client +{ + public class CachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency + { + public IHttpContextAccessor HttpContextAccessor { get; set; } + + protected IHttpClientProxy Proxy { get; } + protected ICurrentUser CurrentUser { get; } + protected IDistributedCache Cache { get; } + + public CachedApplicationConfigurationClient( + IDistributedCache cache, + IHttpClientProxy proxy, + ICurrentUser currentUser, + IHttpContextAccessor httpContextAccessor) + { + Proxy = proxy; + CurrentUser = currentUser; + HttpContextAccessor = httpContextAccessor; + Cache = cache; + } + + public async Task GetAsync() + { + var cacheKey = CreateCacheKey(); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) + { + return configuration; + } + + configuration = await Cache.GetOrAddAsync( + CreateCacheKey(), + async () => await Proxy.Service.GetAsync(), + () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5) + } + ); + + if (httpContext != null) + { + httpContext.Items[cacheKey] = configuration; + } + + return configuration; + } + + protected virtual string CreateCacheKey() + { + return $"ApplicationConfiguration_{CurrentUser.Id?.ToString("N") ?? "Anonymous"}"; + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs new file mode 100644 index 0000000000..71d9d8cddf --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/ICachedApplicationConfigurationClient.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; + +namespace Volo.Abp.AspNetCore.Mvc.Client +{ + public interface ICachedApplicationConfigurationClient + { + Task GetAsync(); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs new file mode 100644 index 0000000000..46e13bcc3d --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemotePermissionChecker.cs @@ -0,0 +1,32 @@ +using System.Security.Claims; +using System.Threading.Tasks; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.Client +{ + public class RemotePermissionChecker : IPermissionChecker, ITransientDependency + { + protected ICachedApplicationConfigurationClient ConfigurationClient { get; } + + public RemotePermissionChecker(ICachedApplicationConfigurationClient configurationClient) + { + ConfigurationClient = configurationClient; + } + + public async Task CheckAsync(string name) + { + var configuration = await ConfigurationClient.GetAsync(); + + return new PermissionGrantInfo( + name, + configuration.Auth.GrantedPolicies.ContainsKey(name) + ); + } + + public Task CheckAsync(ClaimsPrincipal claimsPrincipal, string name) + { + return CheckAsync(name); + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs index 4981955ba0..39b3ca394b 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationAuthConfigurationDto.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { + [Serializable] public class ApplicationAuthConfigurationDto { public Dictionary Policies { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs index d7aab53482..ecafcb3274 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs @@ -1,9 +1,14 @@ -namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { + [Serializable] public class ApplicationConfigurationDto { public ApplicationLocalizationConfigurationDto Localization { get; set; } public ApplicationAuthConfigurationDto Auth { get; set; } + + public CurrentUserDto CurrentUser { get; set; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs index 716061d507..05b5d8c7a6 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationLocalizationConfigurationDto.cs @@ -1,7 +1,9 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { + [Serializable] public class ApplicationLocalizationConfigurationDto { public Dictionary> Values { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/CurrentUserDto.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/CurrentUserDto.cs new file mode 100644 index 0000000000..702af56dba --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/CurrentUserDto.cs @@ -0,0 +1,16 @@ +using System; + +namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations +{ + [Serializable] + public class CurrentUserDto + { + public bool IsAuthenticated { get; set; } + + public Guid? Id { get; set; } + + public Guid? TenantId { get; set; } + + public string UserName { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs index 17c1d78911..a91cdebc35 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Authorization; using Volo.Abp.Localization; +using Volo.Abp.Users; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { @@ -17,16 +18,19 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations private readonly IServiceProvider _serviceProvider; private readonly IAbpAuthorizationPolicyProvider _abpAuthorizationPolicyProvider; private readonly IAuthorizationService _authorizationService; + private readonly ICurrentUser _currentUser; public AbpApplicationConfigurationAppService( IOptions localizationOptions, IServiceProvider serviceProvider, IAbpAuthorizationPolicyProvider abpAuthorizationPolicyProvider, - IAuthorizationService authorizationService) + IAuthorizationService authorizationService, + ICurrentUser currentUser) { _serviceProvider = serviceProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; _authorizationService = authorizationService; + _currentUser = currentUser; _localizationOptions = localizationOptions.Value; } @@ -37,7 +41,19 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations return new ApplicationConfigurationDto { Auth = await GetAuthConfig(), - Localization = GetLocalizationConfig() + Localization = GetLocalizationConfig(), + CurrentUser = GetCurrentUser() + }; + } + + protected virtual CurrentUserDto GetCurrentUser() + { + return new CurrentUserDto + { + IsAuthenticated = _currentUser.IsAuthenticated, + Id = _currentUser.Id, + TenantId = _currentUser.TenantId, + UserName = _currentUser.UserName }; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs index 98e6d41b8e..98e09ff9a8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations { [Route("api/abp/application-configuration")] - public class AbpApplicationConfigurationController : AbpController + public class AbpApplicationConfigurationController : AbpController, IAbpApplicationConfigurationAppService { private readonly IAbpApplicationConfigurationAppService _applicationConfigurationAppService; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index 156e4114ae..1a9646d13f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -79,6 +79,7 @@ namespace Volo.Abp.AspNetCore.Mvc return; } + Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}"); var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create( uniqueMethodName, method, diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs index a5ef33e83b..2a5f8871c1 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel/Volo/Abp/Http/Client/IdentityModel/IdentityModelRemoteServiceHttpClientAuthenticator.cs @@ -1,4 +1,4 @@ -using System.Net.Http.Headers; +using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; @@ -26,9 +26,7 @@ namespace Volo.Abp.Http.Client.IdentityModel if (accessToken != null) { - //TODO: "Bearer" should be configurable - context.Client.DefaultRequestHeaders.Authorization - = new AuthenticationHeaderValue("Bearer", accessToken); + context.Client.SetBearerToken(accessToken); } else { From caad208049e341afba37581d6530c57bb2f8dca6 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 11 Jan 2019 14:37:39 +0300 Subject: [PATCH 16/23] Update AbpPaginationTagHelperService.cs --- .../TagHelpers/Pagination/AbpPaginationTagHelperService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Pagination/AbpPaginationTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Pagination/AbpPaginationTagHelperService.cs index 6fda6ccd63..629cad0b66 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Pagination/AbpPaginationTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Pagination/AbpPaginationTagHelperService.cs @@ -158,7 +158,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination pagerInfo + "
\r\n" + "