diff --git a/Volo.Abp.v3.ncrunchsolution b/Volo.Abp.v3.ncrunchsolution
new file mode 100644
index 0000000000..10420ac91d
--- /dev/null
+++ b/Volo.Abp.v3.ncrunchsolution
@@ -0,0 +1,6 @@
+
+
+ True
+ True
+
+
\ No newline at end of file
diff --git a/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.v3.ncrunchproject b/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.v3.ncrunchproject
new file mode 100644
index 0000000000..eacd190144
--- /dev/null
+++ b/src/AbpDesk/AbpDesk.Application/AbpDesk.Application.v3.ncrunchproject
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
index 9c97479cf6..e47b9ef42e 100644
--- a/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
+++ b/src/AbpDesk/AbpDesk.ConsoleDemo/AbpDesk/ConsoleDemo/Program.cs
@@ -9,9 +9,11 @@ namespace AbpDesk.ConsoleDemo
public static void Main(string[] args)
{
var services = new ServiceCollection();
- using (var application = AbpApplication.Create(services))
+ var application = AbpApplication.Create(services);
+
+ using (var scope = services.BuildServiceProvider().CreateScope())
{
- application.Initialize(services.BuildServiceProvider());
+ application.Initialize(scope.ServiceProvider);
application
.ServiceProvider
@@ -19,6 +21,8 @@ namespace AbpDesk.ConsoleDemo
.List();
Console.ReadLine();
+
+ application.Shutdown();
}
}
}
diff --git a/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs b/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs
deleted file mode 100644
index 4606296b4c..0000000000
--- a/src/Volo.Abp.AspNetCore/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs
+++ /dev/null
@@ -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(this IServiceCollection services)
- where TStartupModule : IAbpModule
- {
- return AbpApplication.Create(services);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Volo.Abp.TestBase/AbpIntegratedTest.cs b/src/Volo.Abp.TestBase/AbpIntegratedTest.cs
index 41fa62589e..447ea0be31 100644
--- a/src/Volo.Abp.TestBase/AbpIntegratedTest.cs
+++ b/src/Volo.Abp.TestBase/AbpIntegratedTest.cs
@@ -14,8 +14,11 @@ namespace Volo.Abp.TestBase
public AbpIntegratedTest()
{
var services = CreateServiceCollection();
+
Application = AbpApplication.Create(services);
+
var serviceProvider = CreateServiceProvider(services);
+
Application.Initialize(serviceProvider);
}
@@ -31,7 +34,7 @@ namespace Volo.Abp.TestBase
public void Dispose()
{
- Application.Dispose();
+ Application.Shutdown();
}
}
}
diff --git a/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs b/src/Volo.Abp/Microsoft/Extensions/DependencyInjection/AbpServiceCollectionExtensions.cs
new file mode 100644
index 0000000000..d5428f6c5a
--- /dev/null
+++ b/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(
+ [NotNull] this IServiceCollection services)
+ where TStartupModule : IAbpModule
+ {
+ return AbpApplication.Create(services);
+ }
+
+ public static AbpApplication AddApplication(
+ [NotNull] this IServiceCollection services,
+ [CanBeNull] Action optionsAction)
+ where TStartupModule : IAbpModule
+ {
+ return AbpApplication.Create(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 optionsAction)
+ {
+ return AbpApplication.Create(startupModuleType, services, optionsAction);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/AbpApplication.cs b/src/Volo.Abp/Volo/Abp/AbpApplication.cs
index 5b4386c2ea..d18316057a 100644
--- a/src/Volo.Abp/Volo/Abp/AbpApplication.cs
+++ b/src/Volo.Abp/Volo/Abp/AbpApplication.cs
@@ -1,25 +1,31 @@
using System;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
+using Volo.Abp.Internal;
using Volo.Abp.Modularity;
namespace Volo.Abp
{
- public class AbpApplication : IDisposable
+ public class AbpApplication
{
public Type StartupModuleType { get; }
public IServiceProvider ServiceProvider { get; private set; }
- private AbpApplication(Type startupModuleType, IServiceCollection services, Action optionsAction)
+ private AbpApplication(
+ [NotNull] Type startupModuleType,
+ [NotNull] IServiceCollection services,
+ [CanBeNull] Action 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);
- AddServices(services);
+ services.AddCoreAbpServices(this);
LoadModules(services, options);
}
@@ -31,34 +37,49 @@ namespace Volo.Abp
public static AbpApplication Create(
[NotNull] IServiceCollection services,
- [CanBeNull] Action optionsAction)
+ [CanBeNull] Action optionsAction)
where TStartupModule : IAbpModule
{
- Check.NotNull(services, nameof(services));
-
return new AbpApplication(typeof(TStartupModule), services, optionsAction);
}
- public void Initialize(IServiceProvider serviceProvider)
+ public static AbpApplication Create(
+ [NotNull] Type startupModuleType,
+ [NotNull] IServiceCollection services)
{
- ServiceProvider = serviceProvider;
- ServiceProvider.GetRequiredService().Initialize();
+ return Create(startupModuleType, services, null);
}
- private void AddServices(IServiceCollection services)
+ public static AbpApplication Create(
+ [NotNull] Type startupModuleType,
+ [NotNull] IServiceCollection services,
+ [CanBeNull] Action optionsAction)
{
- services.AddSingleton(this);
- services.AddCoreAbpServices();
+ return new AbpApplication(startupModuleType, services, optionsAction);
}
- private void LoadModules(IServiceCollection services, AbpApplicationOptions options)
+ public void Initialize([NotNull] IServiceProvider serviceProvider)
{
- services.GetSingletonInstance().LoadAll(services, StartupModuleType, options.PlugInSources);
+ Check.NotNull(serviceProvider, nameof(serviceProvider));
+
+ ServiceProvider = serviceProvider;
+ ServiceProvider.GetRequiredService().InitializeModules();
}
- public void Dispose()
+ private void LoadModules(IServiceCollection services, AbpApplicationCreationOptions options)
{
+ services
+ .GetSingletonInstance()
+ .LoadAll(
+ services,
+ StartupModuleType,
+ options.PlugInSources
+ );
+ }
+ public void Shutdown()
+ {
+ //TODO: Shutdown modules
}
}
}
diff --git a/src/Volo.Abp/Volo/Abp/AbpApplicationCreationOptions.cs b/src/Volo.Abp/Volo/Abp/AbpApplicationCreationOptions.cs
new file mode 100644
index 0000000000..2c13bb6c5c
--- /dev/null
+++ b/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();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/AbpApplicationOptions.cs b/src/Volo.Abp/Volo/Abp/AbpApplicationOptions.cs
deleted file mode 100644
index ed8260fc8c..0000000000
--- a/src/Volo.Abp/Volo/Abp/AbpApplicationOptions.cs
+++ /dev/null
@@ -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();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/AbpException.cs b/src/Volo.Abp/Volo/Abp/AbpException.cs
index 10418a4088..bf1c35456d 100644
--- a/src/Volo.Abp/Volo/Abp/AbpException.cs
+++ b/src/Volo.Abp/Volo/Abp/AbpException.cs
@@ -2,6 +2,8 @@
namespace Volo.Abp
{
+ //TODO: Make Exceptions [Serializable] when it's available in .Net Standard 2.0.
+
///
/// Base exception type for those are thrown by Abp system for Abp specific exceptions.
///
diff --git a/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs b/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
index 1b10d0fe6a..ca58482d9c 100644
--- a/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
+++ b/src/Volo.Abp/Volo/Abp/AbpKernelModule.cs
@@ -8,6 +8,7 @@ namespace Volo.Abp
public override void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
+
services.AddAssemblyOf();
}
}
diff --git a/src/Volo.Abp/Volo/Abp/DisposeAction.cs b/src/Volo.Abp/Volo/Abp/DisposeAction.cs
index 116249e58c..8057508e29 100644
--- a/src/Volo.Abp/Volo/Abp/DisposeAction.cs
+++ b/src/Volo.Abp/Volo/Abp/DisposeAction.cs
@@ -1,4 +1,5 @@
using System;
+using JetBrains.Annotations;
namespace Volo.Abp
{
@@ -14,7 +15,7 @@ namespace Volo.Abp
/// Creates a new object.
///
/// Action to be executed when this object is disposed.
- public DisposeAction(Action action)
+ public DisposeAction([NotNull] Action action)
{
Check.NotNull(action, nameof(action));
diff --git a/src/Volo.Abp/Volo/Abp/AbpServiceCollectionExtensions.cs b/src/Volo.Abp/Volo/Abp/Internal/InternalServiceCollectionExtensions.cs
similarity index 62%
rename from src/Volo.Abp/Volo/Abp/AbpServiceCollectionExtensions.cs
rename to src/Volo.Abp/Volo/Abp/Internal/InternalServiceCollectionExtensions.cs
index bfce64a28c..7cff8bf66c 100644
--- a/src/Volo.Abp/Volo/Abp/AbpServiceCollectionExtensions.cs
+++ b/src/Volo.Abp/Volo/Abp/Internal/InternalServiceCollectionExtensions.cs
@@ -2,12 +2,13 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
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(new ModuleLoader());
}
}
diff --git a/src/Volo.Abp/Volo/Abp/Modularity/IAbpModule.cs b/src/Volo.Abp/Volo/Abp/Modularity/IAbpModule.cs
index a2b397c49c..15c7fcca13 100644
--- a/src/Volo.Abp/Volo/Abp/Modularity/IAbpModule.cs
+++ b/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;
namespace Volo.Abp.Modularity
{
public interface IAbpModule : ISingletonDependency
{
- void ConfigureServices(IServiceCollection services);
+ void ConfigureServices([NotNull] IServiceCollection services);
}
}
diff --git a/src/Volo.Abp/Volo/Abp/Modularity/IModuleInitializationManager.cs b/src/Volo.Abp/Volo/Abp/Modularity/IModuleInitializationManager.cs
new file mode 100644
index 0000000000..c72d8bc6ed
--- /dev/null
+++ b/src/Volo.Abp/Volo/Abp/Modularity/IModuleInitializationManager.cs
@@ -0,0 +1,7 @@
+namespace Volo.Abp.Modularity
+{
+ public interface IModuleInitializationManager
+ {
+ void InitializeModules();
+ }
+}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/Modularity/IModuleManager.cs b/src/Volo.Abp/Volo/Abp/Modularity/IModuleManager.cs
deleted file mode 100644
index 446645bcae..0000000000
--- a/src/Volo.Abp/Volo/Abp/Modularity/IModuleManager.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Volo.Abp.Modularity
-{
- public interface IModuleManager
- {
- void Initialize();
- }
-}
\ No newline at end of file
diff --git a/src/Volo.Abp/Volo/Abp/Modularity/ModuleManager.cs b/src/Volo.Abp/Volo/Abp/Modularity/ModuleInitializationManager.cs
similarity index 70%
rename from src/Volo.Abp/Volo/Abp/Modularity/ModuleManager.cs
rename to src/Volo.Abp/Volo/Abp/Modularity/ModuleInitializationManager.cs
index 49474fae33..2cd9255de5 100644
--- a/src/Volo.Abp/Volo/Abp/Modularity/ModuleManager.cs
+++ b/src/Volo.Abp/Volo/Abp/Modularity/ModuleInitializationManager.cs
@@ -3,18 +3,18 @@ using Volo.DependencyInjection;
namespace Volo.Abp.Modularity
{
- public class ModuleManager : IModuleManager, ISingletonDependency
+ public class ModuleInitializationManager : IModuleInitializationManager, ISingletonDependency
{
private readonly IModuleLoader _moduleLoader;
private readonly IEnumerable _initializers;
- public ModuleManager(IModuleLoader moduleLoader, IEnumerable initializers)
+ public ModuleInitializationManager(IModuleLoader moduleLoader, IEnumerable initializers)
{
_moduleLoader = moduleLoader;
_initializers = initializers;
}
- public void Initialize()
+ public void InitializeModules()
{
foreach (var initializer in _initializers)
{
diff --git a/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.v3.ncrunchproject b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.v3.ncrunchproject
new file mode 100644
index 0000000000..95a483b433
--- /dev/null
+++ b/test/AbpDesk/AbpDesk.Application.Tests/AbpDesk.Application.Tests.v3.ncrunchproject
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs b/test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs
index 49aa3ef345..cbf0e68bab 100644
--- a/test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs
+++ b/test/Volo.Abp.Tests/Volo/Abp/AbpApplication_Initialize_Tests.cs
@@ -15,17 +15,23 @@ namespace Volo.Abp
var services = new ServiceCollection();
- using (var application = AbpApplication.Create(services))
- {
- //Act
+ var application = AbpApplication.Create(services);
- application.Initialize(services.BuildServiceProvider());
+ using (var scope = services.BuildServiceProvider().CreateScope())
+ {
+ application.Initialize(scope.ServiceProvider);
//Assert
var module = application.ServiceProvider.GetRequiredService();
module.ConfigureServicesIsCalled.ShouldBeTrue();
module.OnApplicationInitializeIsCalled.ShouldBeTrue();
+
+ //Act
+
+ application.Shutdown();
+
+ //TODO: Assert shutdown module
}
}
@@ -36,21 +42,26 @@ namespace Volo.Abp
var services = new ServiceCollection();
- using (var application = AbpApplication.Create(services, options =>
+ var application = services.AddApplication(options =>
{
options.PlugInSources.AddTypes(typeof(IndependentEmptyPlugInModule));
- }))
- {
- //Act
+ });
- application.Initialize(services.BuildServiceProvider());
+ //Act
- //Assert
+ application.Initialize(services.BuildServiceProvider());
- var plugInModule = application.ServiceProvider.GetRequiredService();
- plugInModule.ConfigureServicesIsCalled.ShouldBeTrue();
- plugInModule.OnApplicationInitializeIsCalled.ShouldBeTrue();
- }
+ //Assert
+
+ var plugInModule = application.ServiceProvider.GetRequiredService();
+ plugInModule.ConfigureServicesIsCalled.ShouldBeTrue();
+ plugInModule.OnApplicationInitializeIsCalled.ShouldBeTrue();
+
+ //Act
+
+ application.Shutdown();
+
+ //TODO: Assert shutdown module
}
}
}
\ No newline at end of file