From 8b4c18d143cba431ec08eba94f26c70fe76152c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 28 Sep 2017 09:44:24 +0300 Subject: [PATCH 1/2] Added a test controller for versioning. --- .../VersioningTests/CallsController.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Volo.Abp.Identity.HttpApi.Host/VersioningTests/CallsController.cs diff --git a/src/Volo.Abp.Identity.HttpApi.Host/VersioningTests/CallsController.cs b/src/Volo.Abp.Identity.HttpApi.Host/VersioningTests/CallsController.cs new file mode 100644 index 0000000000..cf590e964a --- /dev/null +++ b/src/Volo.Abp.Identity.HttpApi.Host/VersioningTests/CallsController.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace Volo.Abp.Identity.HttpApi.Host.VersioningTests +{ + [Route("api/calls")] + public class CallsController : AbpController + { + private static List _calls = new List + { + new CallDto {Id = 1, Number = "123456"}, + new CallDto { Id = 2, Number = "123457" } + }; + + [HttpGet] + public List GetList() + { + return _calls; + } + } + + public class CallDto : EntityDto + { + public string Number { get; set; } + } +} From 36f99942a33d1ba0eb3e89ddfffc4274c39cf088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 28 Sep 2017 14:36:56 +0300 Subject: [PATCH 2/2] Fix serviceprovider reference issue. --- .../EmbeddedResourceFileProvider.cs | 24 +++++++++++++-- .../EmbeddedResourceViewFileProvider.cs | 5 ++-- src/Volo.Abp/Volo/Abp/AbpApplicationBase.cs | 29 ++++++++++++------- ...pApplicationWithExternalServiceProvider.cs | 2 +- ...pApplicationWithInternalServiceProvider.cs | 4 +-- src/Volo.Abp/Volo/Abp/AbpKernelModule.cs | 13 ++------- 6 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceFileProvider.cs b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceFileProvider.cs index ec0a332f22..c59873d1e3 100644 --- a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceFileProvider.cs +++ b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceFileProvider.cs @@ -12,6 +12,7 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles { private readonly Lazy _embeddedResourceManager; private readonly Lazy _options; + private readonly IObjectAccessor _serviceProviderAccessor; public EmbeddedResourceFileProvider(IServiceProvider serviceProvider) : this(new ObjectAccessor(serviceProvider)) @@ -19,21 +20,28 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles } - public EmbeddedResourceFileProvider(IObjectAccessor serviceProvider) + public EmbeddedResourceFileProvider(IObjectAccessor serviceProviderAccessor) { + _serviceProviderAccessor = serviceProviderAccessor; + _embeddedResourceManager = new Lazy( - () => serviceProvider.Value.GetRequiredService(), + () => serviceProviderAccessor.Value.GetRequiredService(), true ); _options = new Lazy( - () => serviceProvider.Value.GetRequiredService>().Value, + () => serviceProviderAccessor.Value.GetRequiredService>().Value, true ); } public IFileInfo GetFileInfo(string subpath) { + if (!IsInitialized()) + { + return new NotFoundFileInfo(subpath); + } + var resource = _embeddedResourceManager.Value.FindFile(subpath); if (resource == null || IsIgnoredFile(resource)) @@ -46,6 +54,11 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles public IDirectoryContents GetDirectoryContents(string subpath) { + if (!IsInitialized()) + { + return new NotFoundDirectoryContents(); + } + //TODO: Implement...? return new NotFoundDirectoryContents(); @@ -60,5 +73,10 @@ namespace Volo.Abp.AspNetCore.EmbeddedFiles { return resource.FileExtension != null && _options.Value.IgnoredFileExtensions.Contains(resource.FileExtension); } + + private bool IsInitialized() + { + return _serviceProviderAccessor.Value != null; + } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceViewFileProvider.cs b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceViewFileProvider.cs index 0974bec33c..61319b0843 100644 --- a/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceViewFileProvider.cs +++ b/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/EmbeddedFiles/EmbeddedResourceViewFileProvider.cs @@ -4,10 +4,11 @@ using Volo.Abp.EmbeddedFiles; namespace Volo.Abp.AspNetCore.EmbeddedFiles { + //TODO: Remove to Volo.Abp.AspNetCore.Mvc project! public class EmbeddedResourceViewFileProvider : EmbeddedResourceFileProvider { - public EmbeddedResourceViewFileProvider(IObjectAccessor serviceProvider) - : base(serviceProvider) + public EmbeddedResourceViewFileProvider(IObjectAccessor serviceProviderAccessor) + : base(serviceProviderAccessor) { } diff --git a/src/Volo.Abp/Volo/Abp/AbpApplicationBase.cs b/src/Volo.Abp/Volo/Abp/AbpApplicationBase.cs index d64e415e7f..f6811ba9be 100644 --- a/src/Volo.Abp/Volo/Abp/AbpApplicationBase.cs +++ b/src/Volo.Abp/Volo/Abp/AbpApplicationBase.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; using Volo.Abp.Internal; using Volo.Abp.Modularity; @@ -12,7 +13,7 @@ namespace Volo.Abp [NotNull] public Type StartupModuleType { get; } - public IServiceProvider ServiceProvider { get; protected set; } + public IServiceProvider ServiceProvider { get; private set; } public IServiceCollection Services { get; } @@ -29,6 +30,8 @@ namespace Volo.Abp StartupModuleType = startupModuleType; Services = services; + services.TryAddObjectAccessor(); + var options = new AbpApplicationCreationOptions(services); optionsAction?.Invoke(options); @@ -50,16 +53,11 @@ namespace Volo.Abp { } - - private IReadOnlyList LoadModules(IServiceCollection services, AbpApplicationCreationOptions options) + + protected virtual void SetServiceProvider(IServiceProvider serviceProvider) { - return services - .GetSingletonInstance() - .LoadModules( - services, - StartupModuleType, - options.PlugInSources - ); + ServiceProvider = serviceProvider; + ServiceProvider.GetRequiredService>().Value = ServiceProvider; } protected virtual void InitializeModules() @@ -71,5 +69,16 @@ namespace Volo.Abp .InitializeModules(new ApplicationInitializationContext(scope.ServiceProvider)); } } + + private IReadOnlyList LoadModules(IServiceCollection services, AbpApplicationCreationOptions options) + { + return services + .GetSingletonInstance() + .LoadModules( + services, + StartupModuleType, + options.PlugInSources + ); + } } } \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs b/src/Volo.Abp/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs index ea846809fa..1becd3be9b 100644 --- a/src/Volo.Abp/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs +++ b/src/Volo.Abp/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs @@ -22,7 +22,7 @@ namespace Volo.Abp { Check.NotNull(serviceProvider, nameof(serviceProvider)); - ServiceProvider = serviceProvider; + SetServiceProvider(serviceProvider); InitializeModules(); } diff --git a/src/Volo.Abp/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs b/src/Volo.Abp/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs index da27610c4a..2ba93dd513 100644 --- a/src/Volo.Abp/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs +++ b/src/Volo.Abp/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs @@ -34,8 +34,8 @@ namespace Volo.Abp public void Initialize() { ServiceScope = Services.BuildServiceProviderFromFactory().CreateScope(); - ServiceProvider = ServiceScope.ServiceProvider; - + SetServiceProvider(ServiceScope.ServiceProvider); + InitializeModules(); } diff --git a/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs b/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs index 3f3e42aadf..49966bad54 100644 --- a/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs +++ b/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs @@ -1,6 +1,4 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; using Volo.Abp.ObjectMapping; using Volo.Abp.Reflection; @@ -35,9 +33,7 @@ namespace Volo.Abp services.AddLogging(); services.AddAssemblyOf(); - - services.TryAddObjectAccessor(); - + services.Configure(options => { options.Contributers.Add(); @@ -46,10 +42,5 @@ namespace Volo.Abp options.Contributers.Add(); }); } - - public override void OnApplicationInitialization(ApplicationInitializationContext context) - { - context.ServiceProvider.GetRequiredService>().Value = context.ServiceProvider; - } } }