mirror of https://github.com/abpframework/abp.git
13 changed files with 178 additions and 110 deletions
@ -1,94 +0,0 @@ |
|||||
using System; |
|
||||
using JetBrains.Annotations; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.Internal; |
|
||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace Volo.Abp |
|
||||
{ |
|
||||
public class AbpApplication |
|
||||
{ |
|
||||
[NotNull] |
|
||||
public Type StartupModuleType { get; } |
|
||||
|
|
||||
public IServiceProvider ServiceProvider { get; private set; } |
|
||||
|
|
||||
[NotNull] |
|
||||
internal AbpModuleDescriptor[] Modules { get; } |
|
||||
|
|
||||
private AbpApplication( |
|
||||
[NotNull] Type startupModuleType, |
|
||||
[NotNull] IServiceCollection services, |
|
||||
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
|
||||
{ |
|
||||
Check.NotNull(startupModuleType, nameof(startupModuleType)); |
|
||||
Check.NotNull(services, nameof(services)); |
|
||||
|
|
||||
StartupModuleType = startupModuleType; |
|
||||
|
|
||||
var options = new AbpApplicationCreationOptions(services); |
|
||||
optionsAction?.Invoke(options); |
|
||||
|
|
||||
services.AddCoreAbpServices(this); |
|
||||
Modules = LoadModules(services, options); |
|
||||
} |
|
||||
|
|
||||
internal static AbpApplication Create<TStartupModule>([NotNull] IServiceCollection services) |
|
||||
where TStartupModule : IAbpModule |
|
||||
{ |
|
||||
return Create<TStartupModule>(services, null); |
|
||||
} |
|
||||
|
|
||||
internal static AbpApplication Create<TStartupModule>( |
|
||||
[NotNull] IServiceCollection services, |
|
||||
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
|
||||
where TStartupModule : IAbpModule |
|
||||
{ |
|
||||
return new AbpApplication(typeof(TStartupModule), services, optionsAction); |
|
||||
} |
|
||||
|
|
||||
internal static AbpApplication Create( |
|
||||
[NotNull] Type startupModuleType, |
|
||||
[NotNull] IServiceCollection services) |
|
||||
{ |
|
||||
return Create(startupModuleType, services, null); |
|
||||
} |
|
||||
|
|
||||
internal static AbpApplication Create( |
|
||||
[NotNull] Type startupModuleType, |
|
||||
[NotNull] IServiceCollection services, |
|
||||
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
|
||||
{ |
|
||||
return new AbpApplication(startupModuleType, services, optionsAction); |
|
||||
} |
|
||||
|
|
||||
public void Initialize([NotNull] IServiceProvider serviceProvider) |
|
||||
{ |
|
||||
Check.NotNull(serviceProvider, nameof(serviceProvider)); |
|
||||
|
|
||||
ServiceProvider = serviceProvider; |
|
||||
|
|
||||
ServiceProvider |
|
||||
.GetRequiredService<IModuleManager>() |
|
||||
.InitializeModules(new ApplicationInitializationContext(serviceProvider)); |
|
||||
} |
|
||||
|
|
||||
private AbpModuleDescriptor[] LoadModules(IServiceCollection services, AbpApplicationCreationOptions options) |
|
||||
{ |
|
||||
return services |
|
||||
.GetSingletonInstance<IModuleLoader>() |
|
||||
.LoadModules( |
|
||||
services, |
|
||||
StartupModuleType, |
|
||||
options.PlugInSources |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public void Shutdown() |
|
||||
{ |
|
||||
ServiceProvider |
|
||||
.GetRequiredService<IModuleManager>() |
|
||||
.ShutdownModules(new ApplicationShutdownContext()); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,56 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Internal; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public abstract class AbpApplicationBase : IAbpApplication |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public Type StartupModuleType { get; } |
||||
|
|
||||
|
public IServiceProvider ServiceProvider { get; protected set; } |
||||
|
|
||||
|
[NotNull] |
||||
|
public AbpModuleDescriptor[] Modules { get; } |
||||
|
|
||||
|
internal AbpApplicationBase( |
||||
|
[NotNull] Type startupModuleType, |
||||
|
[NotNull] IServiceCollection services, |
||||
|
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
||||
|
{ |
||||
|
Check.NotNull(startupModuleType, nameof(startupModuleType)); |
||||
|
Check.NotNull(services, nameof(services)); |
||||
|
|
||||
|
StartupModuleType = startupModuleType; |
||||
|
|
||||
|
var options = new AbpApplicationCreationOptions(services); |
||||
|
optionsAction?.Invoke(options); |
||||
|
|
||||
|
services.AddSingleton<IAbpApplication>(_ => this); |
||||
|
services.AddCoreAbpServices(); |
||||
|
|
||||
|
Modules = LoadModules(services, options); |
||||
|
} |
||||
|
|
||||
|
private AbpModuleDescriptor[] LoadModules(IServiceCollection services, AbpApplicationCreationOptions options) |
||||
|
{ |
||||
|
return services |
||||
|
.GetSingletonInstance<IModuleLoader>() |
||||
|
.LoadModules( |
||||
|
services, |
||||
|
StartupModuleType, |
||||
|
options.PlugInSources |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public void Shutdown() //TODO: Why not disposable?
|
||||
|
{ |
||||
|
ServiceProvider |
||||
|
.GetRequiredService<IModuleManager>() |
||||
|
.ShutdownModules(new ApplicationShutdownContext()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public static class AbpApplicationFactory |
||||
|
{ |
||||
|
public static IAbpApplicationWithExternalServiceProvider Create<TStartupModule>( |
||||
|
[NotNull] IServiceCollection services) |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
return Create<TStartupModule>(services, null); |
||||
|
} |
||||
|
|
||||
|
public static IAbpApplicationWithExternalServiceProvider Create<TStartupModule>( |
||||
|
[NotNull] IServiceCollection services, |
||||
|
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
return new AbpApplicationWithExternalServiceProvider(typeof(TStartupModule), services, optionsAction); |
||||
|
} |
||||
|
|
||||
|
public static IAbpApplicationWithExternalServiceProvider Create( |
||||
|
[NotNull] Type startupModuleType, |
||||
|
[NotNull] IServiceCollection services) |
||||
|
{ |
||||
|
return Create(startupModuleType, services, null); |
||||
|
} |
||||
|
|
||||
|
public static IAbpApplicationWithExternalServiceProvider Create( |
||||
|
[NotNull] Type startupModuleType, |
||||
|
[NotNull] IServiceCollection services, |
||||
|
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction) |
||||
|
{ |
||||
|
return new AbpApplicationWithExternalServiceProvider(startupModuleType, services, optionsAction); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
internal class AbpApplicationWithExternalServiceProvider : AbpApplicationBase, IAbpApplicationWithExternalServiceProvider |
||||
|
{ |
||||
|
public AbpApplicationWithExternalServiceProvider( |
||||
|
[NotNull] Type startupModuleType, |
||||
|
[NotNull] IServiceCollection services, |
||||
|
[CanBeNull] Action<AbpApplicationCreationOptions> optionsAction |
||||
|
) : base( |
||||
|
startupModuleType, |
||||
|
services, |
||||
|
optionsAction) |
||||
|
{ |
||||
|
services.AddSingleton<IAbpApplicationWithExternalServiceProvider>(_ => this); |
||||
|
} |
||||
|
|
||||
|
public void Initialize(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
Check.NotNull(serviceProvider, nameof(serviceProvider)); |
||||
|
|
||||
|
ServiceProvider = serviceProvider; |
||||
|
|
||||
|
ServiceProvider |
||||
|
.GetRequiredService<IModuleManager>() |
||||
|
.InitializeModules(new ApplicationInitializationContext(serviceProvider)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public interface IAbpApplication |
||||
|
{ |
||||
|
Type StartupModuleType { get; } |
||||
|
|
||||
|
IServiceProvider ServiceProvider { get; } |
||||
|
|
||||
|
AbpModuleDescriptor[] Modules { get; } |
||||
|
|
||||
|
void Shutdown(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public interface IAbpApplicationWithExternalServiceProvider : IAbpApplication |
||||
|
{ |
||||
|
void Initialize([NotNull] IServiceProvider serviceProvider); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public interface IAbpApplicationWithInternalServiceProvider : IAbpApplication |
||||
|
{ |
||||
|
void Initialize(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue