Browse Source

Refactorings.

pull/81/head
Halil İbrahim Kalkan 10 years ago
parent
commit
fc14608b08
  1. 6
      Volo.Abp.v3.ncrunchsolution
  2. 7
      src/AbpDesk/AbpDesk.Application/AbpDesk.Application.v3.ncrunchproject
  3. 8
      src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
  4. 15
      src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs
  5. 5
      src/Volo.Abp.TestBase/AbpIntegratedTest.cs
  6. 40
      src/Volo.Abp/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs
  7. 55
      src/Volo.Abp/Volo/Abp/AbpApplication.cs
  8. 14
      src/Volo.Abp/Volo/Abp/AbpApplicationCreationOptions.cs
  9. 14
      src/Volo.Abp/Volo/Abp/AbpApplicationOptions.cs
  10. 2
      src/Volo.Abp/Volo/Abp/AbpException.cs
  11. 1
      src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
  12. 3
      src/Volo.Abp/Volo/Abp/DisposeAction.cs
  13. 7
      src/Volo.Abp/Volo/Abp/Internal/InternalServiceCollectionExtensions.cs
  14. 5
      src/Volo.Abp/Volo/Abp/Modularity/IAbpModule.cs
  15. 7
      src/Volo.Abp/Volo/Abp/Modularity/IModuleInitializationManager.cs
  16. 7
      src/Volo.Abp/Volo/Abp/Modularity/IModuleManager.cs
  17. 6
      src/Volo.Abp/Volo/Abp/Modularity/ModuleInitializationManager.cs
  18. 3
      test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.v3.ncrunchproject
  19. 39
      test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs

6
Volo.Abp.v3.ncrunchsolution

@ -0,0 +1,6 @@
<SolutionConfiguration>
<Settings>
<AllowParallelTestExecution>True</AllowParallelTestExecution>
<SolutionConfigured>True</SolutionConfigured>
</Settings>
</SolutionConfiguration>

7
src/AbpDesk/AbpDesk.Application/AbpDesk.Application.v3.ncrunchproject

@ -0,0 +1,7 @@
<ProjectConfiguration>
<Settings>
<IgnoredTests>
<AllTestsSelector />
</IgnoredTests>
</Settings>
</ProjectConfiguration>

8
src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs

@ -9,9 +9,11 @@ namespace AbpDesk.ConsoleDemo
public static void Main(string[] args) public static void Main(string[] args)
{ {
var services = new ServiceCollection(); var services = new ServiceCollection();
using (var application = AbpApplication.Create<AbpDeskConsoleDemoModule>(services)) var application = AbpApplication.Create<AbpDeskConsoleDemoModule>(services);
using (var scope = services.BuildServiceProvider().CreateScope())
{ {
application.Initialize(services.BuildServiceProvider()); application.Initialize(scope.ServiceProvider);
application application
.ServiceProvider .ServiceProvider
@ -19,6 +21,8 @@ namespace AbpDesk.ConsoleDemo
.List(); .List();
Console.ReadLine(); Console.ReadLine();
application.Shutdown();
} }
} }
} }

15
src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs

@ -1,15 +0,0 @@
using Volo.Abp;
using Volo.Abp.Modularity;
namespace Microsoft.Extensions.DependencyInjection
{
//TODO: Decide to move ABP?
public static class AbpServiceCollectionExtensions
{
public static AbpApplication AddApplication<TStartupModule>(this IServiceCollection services)
where TStartupModule : IAbpModule
{
return AbpApplication.Create<TStartupModule>(services);
}
}
}

5
src/Volo.Abp.TestBase/AbpIntegratedTest.cs

@ -14,8 +14,11 @@ namespace Volo.Abp.TestBase
public AbpIntegratedTest() public AbpIntegratedTest()
{ {
var services = CreateServiceCollection(); var services = CreateServiceCollection();
Application = AbpApplication.Create<TStartupModule>(services); Application = AbpApplication.Create<TStartupModule>(services);
var serviceProvider = CreateServiceProvider(services); var serviceProvider = CreateServiceProvider(services);
Application.Initialize(serviceProvider); Application.Initialize(serviceProvider);
} }
@ -31,7 +34,7 @@ namespace Volo.Abp.TestBase
public void Dispose() public void Dispose()
{ {
Application.Dispose(); Application.Shutdown();
} }
} }
} }

40
src/Volo.Abp/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs

@ -0,0 +1,40 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Modularity;
namespace Microsoft.Extensions.DependencyInjection
{
public static class AbpServiceCollectionExtensions
{
public static AbpApplication AddApplication<TStartupModule>(
[NotNull] this IServiceCollection services)
where TStartupModule : IAbpModule
{
return AbpApplication.Create<TStartupModule>(services);
}
public static AbpApplication AddApplication<TStartupModule>(
[NotNull] this IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction)
where TStartupModule : IAbpModule
{
return AbpApplication.Create<TStartupModule>(services, optionsAction);
}
public static AbpApplication AddApplication(
[NotNull] this IServiceCollection services,
[NotNull] Type startupModuleType)
{
return AbpApplication.Create(startupModuleType, services);
}
public static AbpApplication AddApplication(
[NotNull] this IServiceCollection services,
[NotNull] Type startupModuleType,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction)
{
return AbpApplication.Create(startupModuleType, services, optionsAction);
}
}
}

55
src/Volo.Abp/Volo/Abp/AbpApplication.cs

@ -1,25 +1,31 @@
using System; using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Internal;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp namespace Volo.Abp
{ {
public class AbpApplication : IDisposable public class AbpApplication
{ {
public Type StartupModuleType { get; } public Type StartupModuleType { get; }
public IServiceProvider ServiceProvider { get; private set; } public IServiceProvider ServiceProvider { get; private set; }
private AbpApplication(Type startupModuleType, IServiceCollection services, Action<AbpApplicationOptions> optionsAction) private AbpApplication(
[NotNull] Type startupModuleType,
[NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction)
{ {
StartupModuleType = startupModuleType; Check.NotNull(startupModuleType, nameof(startupModuleType));
Check.NotNull(services, nameof(services));
var options = new AbpApplicationOptions(); StartupModuleType = startupModuleType;
var options = new AbpApplicationCreationOptions();
optionsAction?.Invoke(options); optionsAction?.Invoke(options);
AddServices(services); services.AddCoreAbpServices(this);
LoadModules(services, options); LoadModules(services, options);
} }
@ -31,34 +37,49 @@ namespace Volo.Abp
public static AbpApplication Create<TStartupModule>( public static AbpApplication Create<TStartupModule>(
[NotNull] IServiceCollection services, [NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationOptions> optionsAction) [CanBeNull] Action<AbpApplicationCreationOptions> optionsAction)
where TStartupModule : IAbpModule where TStartupModule : IAbpModule
{ {
Check.NotNull(services, nameof(services));
return new AbpApplication(typeof(TStartupModule), services, optionsAction); return new AbpApplication(typeof(TStartupModule), services, optionsAction);
} }
public void Initialize(IServiceProvider serviceProvider) public static AbpApplication Create(
[NotNull] Type startupModuleType,
[NotNull] IServiceCollection services)
{ {
ServiceProvider = serviceProvider; return Create(startupModuleType, services, null);
ServiceProvider.GetRequiredService<IModuleManager>().Initialize();
} }
private void AddServices(IServiceCollection services) public static AbpApplication Create(
[NotNull] Type startupModuleType,
[NotNull] IServiceCollection services,
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction)
{ {
services.AddSingleton(this); return new AbpApplication(startupModuleType, services, optionsAction);
services.AddCoreAbpServices();
} }
private void LoadModules(IServiceCollection services, AbpApplicationOptions options) public void Initialize([NotNull] IServiceProvider serviceProvider)
{ {
services.GetSingletonInstance<IModuleLoader>().LoadAll(services, StartupModuleType, options.PlugInSources); Check.NotNull(serviceProvider, nameof(serviceProvider));
ServiceProvider = serviceProvider;
ServiceProvider.GetRequiredService<IModuleInitializationManager>().InitializeModules();
} }
public void Dispose() private void LoadModules(IServiceCollection services, AbpApplicationCreationOptions options)
{ {
services
.GetSingletonInstance<IModuleLoader>()
.LoadAll(
services,
StartupModuleType,
options.PlugInSources
);
}
public void Shutdown()
{
//TODO: Shutdown modules
} }
} }
} }

14
src/Volo.Abp/Volo/Abp/AbpApplicationCreationOptions.cs

@ -0,0 +1,14 @@
using Volo.Abp.Modularity.PlugIns;
namespace Volo.Abp
{
public class AbpApplicationCreationOptions
{
public PlugInSourceList PlugInSources { get; private set; }
public AbpApplicationCreationOptions()
{
PlugInSources = new PlugInSourceList();
}
}
}

14
src/Volo.Abp/Volo/Abp/AbpApplicationOptions.cs

@ -1,14 +0,0 @@
using Volo.Abp.Modularity.PlugIns;
namespace Volo.Abp
{
public class AbpApplicationOptions
{
public PlugInSourceList PlugInSources { get; set; }
public AbpApplicationOptions()
{
PlugInSources = new PlugInSourceList();
}
}
}

2
src/Volo.Abp/Volo/Abp/AbpException.cs

@ -2,6 +2,8 @@
namespace Volo.Abp namespace Volo.Abp
{ {
//TODO: Make Exceptions [Serializable] when it's available in .Net Standard 2.0.
/// <summary> /// <summary>
/// Base exception type for those are thrown by Abp system for Abp specific exceptions. /// Base exception type for those are thrown by Abp system for Abp specific exceptions.
/// </summary> /// </summary>

1
src/Volo.Abp/Volo/Abp/AbpKernelModule.cs

@ -8,6 +8,7 @@ namespace Volo.Abp
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)
{ {
services.AddOptions(); services.AddOptions();
services.AddAssemblyOf<AbpKernelModule>(); services.AddAssemblyOf<AbpKernelModule>();
} }
} }

3
src/Volo.Abp/Volo/Abp/DisposeAction.cs

@ -1,4 +1,5 @@
using System; using System;
using JetBrains.Annotations;
namespace Volo.Abp namespace Volo.Abp
{ {
@ -14,7 +15,7 @@ namespace Volo.Abp
/// Creates a new <see cref="DisposeAction"/> object. /// Creates a new <see cref="DisposeAction"/> object.
/// </summary> /// </summary>
/// <param name="action">Action to be executed when this object is disposed.</param> /// <param name="action">Action to be executed when this object is disposed.</param>
public DisposeAction(Action action) public DisposeAction([NotNull] Action action)
{ {
Check.NotNull(action, nameof(action)); Check.NotNull(action, nameof(action));

7
src/Volo.Abp/Volo/Abp/AbpServiceCollectionExtensions.cs → src/Volo.Abp/Volo/Abp/Internal/InternalServiceCollectionExtensions.cs

@ -2,12 +2,13 @@
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
namespace Volo.Abp namespace Volo.Abp.Internal
{ {
public static class AbpServiceCollectionExtensions internal static class InternalServiceCollectionExtensions
{ {
internal static void AddCoreAbpServices(this IServiceCollection services) internal static void AddCoreAbpServices(this IServiceCollection services, AbpApplication application)
{ {
services.AddSingleton(application);
services.TryAddSingleton<IModuleLoader>(new ModuleLoader()); services.TryAddSingleton<IModuleLoader>(new ModuleLoader());
} }
} }

5
src/Volo.Abp/Volo/Abp/Modularity/IAbpModule.cs

@ -1,10 +1,11 @@
using Microsoft.Extensions.DependencyInjection; using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Volo.DependencyInjection; using Volo.DependencyInjection;
namespace Volo.Abp.Modularity namespace Volo.Abp.Modularity
{ {
public interface IAbpModule : ISingletonDependency public interface IAbpModule : ISingletonDependency
{ {
void ConfigureServices(IServiceCollection services); void ConfigureServices([NotNull] IServiceCollection services);
} }
} }

7
src/Volo.Abp/Volo/Abp/Modularity/IModuleInitializationManager.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.Modularity
{
public interface IModuleInitializationManager
{
void InitializeModules();
}
}

7
src/Volo.Abp/Volo/Abp/Modularity/IModuleManager.cs

@ -1,7 +0,0 @@
namespace Volo.Abp.Modularity
{
public interface IModuleManager
{
void Initialize();
}
}

6
src/Volo.Abp/Volo/Abp/Modularity/ModuleManager.cs → src/Volo.Abp/Volo/Abp/Modularity/ModuleInitializationManager.cs

@ -3,18 +3,18 @@ using Volo.DependencyInjection;
namespace Volo.Abp.Modularity namespace Volo.Abp.Modularity
{ {
public class ModuleManager : IModuleManager, ISingletonDependency public class ModuleInitializationManager : IModuleInitializationManager, ISingletonDependency
{ {
private readonly IModuleLoader _moduleLoader; private readonly IModuleLoader _moduleLoader;
private readonly IEnumerable<IModuleInitializer> _initializers; private readonly IEnumerable<IModuleInitializer> _initializers;
public ModuleManager(IModuleLoader moduleLoader, IEnumerable<IModuleInitializer> initializers) public ModuleInitializationManager(IModuleLoader moduleLoader, IEnumerable<IModuleInitializer> initializers)
{ {
_moduleLoader = moduleLoader; _moduleLoader = moduleLoader;
_initializers = initializers; _initializers = initializers;
} }
public void Initialize() public void InitializeModules()
{ {
foreach (var initializer in _initializers) foreach (var initializer in _initializers)
{ {

3
test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.v3.ncrunchproject

@ -0,0 +1,3 @@
<ProjectConfiguration>
<Settings />
</ProjectConfiguration>

39
test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs

@ -15,17 +15,23 @@ namespace Volo.Abp
var services = new ServiceCollection(); var services = new ServiceCollection();
using (var application = AbpApplication.Create<IndependentEmptyModule>(services)) var application = AbpApplication.Create<IndependentEmptyModule>(services);
{
//Act
application.Initialize(services.BuildServiceProvider()); using (var scope = services.BuildServiceProvider().CreateScope())
{
application.Initialize(scope.ServiceProvider);
//Assert //Assert
var module = application.ServiceProvider.GetRequiredService<IndependentEmptyModule>(); var module = application.ServiceProvider.GetRequiredService<IndependentEmptyModule>();
module.ConfigureServicesIsCalled.ShouldBeTrue(); module.ConfigureServicesIsCalled.ShouldBeTrue();
module.OnApplicationInitializeIsCalled.ShouldBeTrue(); module.OnApplicationInitializeIsCalled.ShouldBeTrue();
//Act
application.Shutdown();
//TODO: Assert shutdown module
} }
} }
@ -36,21 +42,26 @@ namespace Volo.Abp
var services = new ServiceCollection(); var services = new ServiceCollection();
using (var application = AbpApplication.Create<IndependentEmptyModule>(services, options => var application = services.AddApplication<IndependentEmptyModule>(options =>
{ {
options.PlugInSources.AddTypes(typeof(IndependentEmptyPlugInModule)); options.PlugInSources.AddTypes(typeof(IndependentEmptyPlugInModule));
})) });
{
//Act
application.Initialize(services.BuildServiceProvider()); //Act
//Assert application.Initialize(services.BuildServiceProvider());
var plugInModule = application.ServiceProvider.GetRequiredService<IndependentEmptyPlugInModule>(); //Assert
plugInModule.ConfigureServicesIsCalled.ShouldBeTrue();
plugInModule.OnApplicationInitializeIsCalled.ShouldBeTrue(); var plugInModule = application.ServiceProvider.GetRequiredService<IndependentEmptyPlugInModule>();
} plugInModule.ConfigureServicesIsCalled.ShouldBeTrue();
plugInModule.OnApplicationInitializeIsCalled.ShouldBeTrue();
//Act
application.Shutdown();
//TODO: Assert shutdown module
} }
} }
} }
Loading…
Cancel
Save