mirror of https://github.com/abpframework/abp.git
10 changed files with 118 additions and 23 deletions
@ -0,0 +1,47 @@ |
|||||
|
using System; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp |
||||
|
{ |
||||
|
public class AbpApplication : IDisposable |
||||
|
{ |
||||
|
public Type StartupModuleType { get; } |
||||
|
|
||||
|
private readonly IServiceCollection _services; |
||||
|
private IServiceProvider _serviceProvider; |
||||
|
|
||||
|
private AbpApplication(Type startupModuleType, IServiceCollection services) |
||||
|
{ |
||||
|
StartupModuleType = startupModuleType; |
||||
|
_services = services; |
||||
|
_services.AddCoreAbp(); |
||||
|
} |
||||
|
|
||||
|
public static AbpApplication Create<TStartupModule>(IServiceCollection services) |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
return new AbpApplication(typeof(TStartupModule), services); |
||||
|
} |
||||
|
|
||||
|
public void Start(IServiceProvider serviceProvider) |
||||
|
{ |
||||
|
_serviceProvider = serviceProvider; |
||||
|
_serviceProvider.GetRequiredService<IModuleRunner>().Start(); |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_serviceProvider.GetRequiredService<IModuleRunner>().Stop(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal static class AbpServiceCollectionExtensions |
||||
|
{ |
||||
|
public static void AddCoreAbp(this IServiceCollection services) |
||||
|
{ |
||||
|
services.TryAddSingleton<IModuleRunner, ModuleRunner>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Volo.Abp.Modularity |
||||
|
{ |
||||
|
public interface IModuleRunner |
||||
|
{ |
||||
|
void Start(); |
||||
|
|
||||
|
void Stop(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.Abp.Modularity |
||||
|
{ |
||||
|
public class ModuleRunner : IModuleRunner |
||||
|
{ |
||||
|
public void Start() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void Stop() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Tests.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Tests |
||||
|
{ |
||||
|
public class AbpApplication_Tests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Should_Start_And_Stop_Empty_AbpApplication() |
||||
|
{ |
||||
|
var services = new ServiceCollection(); |
||||
|
|
||||
|
using (var application = AbpApplication.Create<IndependentEmptyModule>(services)) |
||||
|
{ |
||||
|
application.Start(services.BuildServiceProvider()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.Tests.Modularity |
||||
|
{ |
||||
|
public class IndependentEmptyModule : IAbpModule |
||||
|
{ |
||||
|
public void ConfigureServices(IServiceCollection services) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,15 +0,0 @@ |
|||||
using System.Reflection; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Volo.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.Tests.Modularity |
|
||||
{ |
|
||||
public class TestModule : IAbpModule |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddAssembly(typeof(TestModule).GetTypeInfo().Assembly); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,14 +1,21 @@ |
|||||
{ |
{ |
||||
"version": "1.0.0-*", |
"version": "1.0.0-*", |
||||
|
|
||||
|
"testRunner": "xunit", |
||||
|
|
||||
"dependencies": { |
"dependencies": { |
||||
"NETStandard.Library": "1.6.1", |
"AbpTestBase": "1.0.0-*", |
||||
"Volo.Abp": "1.0.0-*" |
"Volo.Abp": "1.0.0-*" |
||||
}, |
}, |
||||
|
|
||||
"frameworks": { |
"frameworks": { |
||||
"netstandard1.6": { |
"netcoreapp1.0": { |
||||
"imports": "dnxcore50" |
"dependencies": { |
||||
|
"Microsoft.NETCore.App": { |
||||
|
"type": "platform", |
||||
|
"version": "1.0.0" |
||||
|
} |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue