mirror of https://github.com/abpframework/abp.git
committed by
GitHub
91 changed files with 1520 additions and 636 deletions
@ -0,0 +1,112 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Net.Http; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Hosting.Server; |
||||
|
using Microsoft.AspNetCore.Routing; |
||||
|
using Microsoft.AspNetCore.TestHost; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.TestBase; |
||||
|
|
||||
|
public class AbpAspNetCoreAsyncIntegratedTestBase<TModule> |
||||
|
where TModule : IAbpModule |
||||
|
{ |
||||
|
protected WebApplication WebApplication { get; set; } |
||||
|
|
||||
|
protected TestServer Server { get; set; } |
||||
|
|
||||
|
protected HttpClient Client { get; set; } |
||||
|
|
||||
|
protected IServiceProvider ServiceProvider { get; set; } |
||||
|
|
||||
|
protected virtual T GetService<T>() |
||||
|
{ |
||||
|
return ServiceProvider.GetService<T>(); |
||||
|
} |
||||
|
|
||||
|
protected virtual T GetRequiredService<T>() |
||||
|
{ |
||||
|
return ServiceProvider.GetRequiredService<T>(); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task InitializeAsync() |
||||
|
{ |
||||
|
var builder = WebApplication.CreateBuilder(); |
||||
|
builder.Host.ConfigureServices(services => |
||||
|
{ |
||||
|
services.AddSingleton<IHostLifetime, TestNoopHostLifetime>(); |
||||
|
services.AddSingleton<IServer, TestServer>(); |
||||
|
}) |
||||
|
.UseAutofac(); |
||||
|
|
||||
|
await builder.Services.AddApplicationAsync<TModule>(options => |
||||
|
{ |
||||
|
options.Services.ReplaceConfiguration(builder.Configuration); |
||||
|
}); |
||||
|
|
||||
|
await ConfigureServicesAsync(builder.Services); |
||||
|
WebApplication = builder.Build(); |
||||
|
await WebApplication.InitializeApplicationAsync(); |
||||
|
await WebApplication.StartAsync(); |
||||
|
|
||||
|
Server = WebApplication.Services.GetRequiredService<IHost>().GetTestServer(); |
||||
|
Client = Server.CreateClient(); |
||||
|
|
||||
|
ServiceProvider = Server.Services; |
||||
|
ServiceProvider.GetRequiredService<ITestServerAccessor>().Server = Server; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task DisposeAsync() |
||||
|
{ |
||||
|
await WebApplication.DisposeAsync(); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task ConfigureServicesAsync(IServiceCollection services) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
#region GetUrl
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>() |
||||
|
{ |
||||
|
return "/" + typeof(TController).Name.RemovePostFix("Controller", "AppService", "ApplicationService", "Service"); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type's given action.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>(string actionName) |
||||
|
{ |
||||
|
return GetUrl<TController>() + "/" + actionName; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets default URL for given controller type's given action with query string parameters (as anonymous object).
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TController">The type of the controller.</typeparam>
|
||||
|
protected virtual string GetUrl<TController>(string actionName, object queryStringParamsAsAnonymousObject) |
||||
|
{ |
||||
|
var url = GetUrl<TController>(actionName); |
||||
|
|
||||
|
var dictionary = new RouteValueDictionary(queryStringParamsAsAnonymousObject); |
||||
|
if (dictionary.Any()) |
||||
|
{ |
||||
|
url += "?" + dictionary.Select(d => $"{d.Key}={d.Value}").JoinAsString("&"); |
||||
|
} |
||||
|
|
||||
|
return url; |
||||
|
} |
||||
|
|
||||
|
#endregion
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.TestBase; |
||||
|
|
||||
|
public class TestNoopHostLifetime : IHostLifetime |
||||
|
{ |
||||
|
public Task StopAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
public Task WaitForStartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,8 +1,11 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp; |
namespace Volo.Abp; |
||||
|
|
||||
public interface IOnApplicationInitialization |
public interface IOnApplicationInitialization |
||||
{ |
{ |
||||
|
Task OnApplicationInitializationAsync([NotNull] ApplicationInitializationContext context); |
||||
|
|
||||
void OnApplicationInitialization([NotNull] ApplicationInitializationContext context); |
void OnApplicationInitialization([NotNull] ApplicationInitializationContext context); |
||||
} |
} |
||||
|
|||||
@ -1,8 +1,11 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp; |
namespace Volo.Abp; |
||||
|
|
||||
public interface IOnApplicationShutdown |
public interface IOnApplicationShutdown |
||||
{ |
{ |
||||
|
Task OnApplicationShutdownAsync([NotNull] ApplicationShutdownContext context); |
||||
|
|
||||
void OnApplicationShutdown([NotNull] ApplicationShutdownContext context); |
void OnApplicationShutdown([NotNull] ApplicationShutdownContext context); |
||||
} |
} |
||||
|
|||||
@ -1,6 +1,10 @@ |
|||||
namespace Volo.Abp.Modularity; |
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IAbpModule |
public interface IAbpModule |
||||
{ |
{ |
||||
|
Task ConfigureServicesAsync(ServiceConfigurationContext context); |
||||
|
|
||||
void ConfigureServices(ServiceConfigurationContext context); |
void ConfigureServices(ServiceConfigurationContext context); |
||||
} |
} |
||||
|
|||||
@ -1,11 +1,16 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IModuleLifecycleContributor : ITransientDependency |
public interface IModuleLifecycleContributor : ITransientDependency |
||||
{ |
{ |
||||
|
Task InitializeAsync([NotNull] ApplicationInitializationContext context, [NotNull] IAbpModule module); |
||||
|
|
||||
void Initialize([NotNull] ApplicationInitializationContext context, [NotNull] IAbpModule module); |
void Initialize([NotNull] ApplicationInitializationContext context, [NotNull] IAbpModule module); |
||||
|
|
||||
|
Task ShutdownAsync([NotNull] ApplicationShutdownContext context, [NotNull] IAbpModule module); |
||||
|
|
||||
void Shutdown([NotNull] ApplicationShutdownContext context, [NotNull] IAbpModule module); |
void Shutdown([NotNull] ApplicationShutdownContext context, [NotNull] IAbpModule module); |
||||
} |
} |
||||
|
|||||
@ -1,10 +1,15 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IModuleManager |
public interface IModuleManager |
||||
{ |
{ |
||||
|
Task InitializeModulesAsync([NotNull] ApplicationInitializationContext context); |
||||
|
|
||||
void InitializeModules([NotNull] ApplicationInitializationContext context); |
void InitializeModules([NotNull] ApplicationInitializationContext context); |
||||
|
|
||||
|
Task ShutdownModulesAsync([NotNull] ApplicationShutdownContext context); |
||||
|
|
||||
void ShutdownModules([NotNull] ApplicationShutdownContext context); |
void ShutdownModules([NotNull] ApplicationShutdownContext context); |
||||
} |
} |
||||
|
|||||
@ -1,8 +1,11 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IOnPostApplicationInitialization |
public interface IOnPostApplicationInitialization |
||||
{ |
{ |
||||
|
Task OnPostApplicationInitializationAsync([NotNull] ApplicationInitializationContext context); |
||||
|
|
||||
void OnPostApplicationInitialization([NotNull] ApplicationInitializationContext context); |
void OnPostApplicationInitialization([NotNull] ApplicationInitializationContext context); |
||||
} |
} |
||||
|
|||||
@ -1,8 +1,11 @@ |
|||||
using JetBrains.Annotations; |
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IOnPreApplicationInitialization |
public interface IOnPreApplicationInitialization |
||||
{ |
{ |
||||
|
Task OnPreApplicationInitializationAsync([NotNull] ApplicationInitializationContext context); |
||||
|
|
||||
void OnPreApplicationInitialization([NotNull] ApplicationInitializationContext context); |
void OnPreApplicationInitialization([NotNull] ApplicationInitializationContext context); |
||||
} |
} |
||||
|
|||||
@ -1,8 +1,10 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IPostConfigureServices |
public interface IPostConfigureServices |
||||
{ |
{ |
||||
|
Task PostConfigureServicesAsync(ServiceConfigurationContext context); |
||||
|
|
||||
void PostConfigureServices(ServiceConfigurationContext context); |
void PostConfigureServices(ServiceConfigurationContext context); |
||||
} |
} |
||||
|
|||||
@ -1,8 +1,10 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.Modularity; |
namespace Volo.Abp.Modularity; |
||||
|
|
||||
public interface IPreConfigureServices |
public interface IPreConfigureServices |
||||
{ |
{ |
||||
|
Task PreConfigureServicesAsync(ServiceConfigurationContext context); |
||||
|
|
||||
void PreConfigureServices(ServiceConfigurationContext context); |
void PreConfigureServices(ServiceConfigurationContext context); |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,70 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace Volo.Abp.Testing; |
||||
|
|
||||
|
public class AbpAsyncIntegratedTest<TStartupModule> : AbpTestBaseWithServiceProvider |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
protected IAbpApplication Application { get; set; } |
||||
|
|
||||
|
protected IServiceProvider RootServiceProvider { get; set; } |
||||
|
|
||||
|
protected IServiceScope TestServiceScope { get; set; } |
||||
|
|
||||
|
public virtual async Task InitializeAsync() |
||||
|
{ |
||||
|
var services = await CreateServiceCollectionAsync(); |
||||
|
|
||||
|
await BeforeAddApplicationAsync(services); |
||||
|
var application = await services.AddApplicationAsync<TStartupModule>(await SetAbpApplicationCreationOptionsAsync()); |
||||
|
await AfterAddApplicationAsync(services); |
||||
|
|
||||
|
RootServiceProvider = await CreateServiceProviderAsync(services); |
||||
|
TestServiceScope = RootServiceProvider.CreateScope(); |
||||
|
await application.InitializeAsync(TestServiceScope.ServiceProvider); |
||||
|
ServiceProvider = application.ServiceProvider; |
||||
|
Application = application; |
||||
|
|
||||
|
await InitializeServicesAsync(); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task DisposeAsync() |
||||
|
{ |
||||
|
await Application.ShutdownAsync(); |
||||
|
TestServiceScope.Dispose(); |
||||
|
Application.Dispose(); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<IServiceCollection> CreateServiceCollectionAsync() |
||||
|
{ |
||||
|
return Task.FromResult<IServiceCollection>(new ServiceCollection()); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task BeforeAddApplicationAsync(IServiceCollection services) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<Action<AbpApplicationCreationOptions>> SetAbpApplicationCreationOptionsAsync() |
||||
|
{ |
||||
|
return Task.FromResult<Action<AbpApplicationCreationOptions>>(_ => { }); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task AfterAddApplicationAsync(IServiceCollection services) |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<IServiceProvider> CreateServiceProviderAsync(IServiceCollection services) |
||||
|
{ |
||||
|
return Task.FromResult(services.BuildServiceProviderFromFactory()); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task InitializeServicesAsync() |
||||
|
{ |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.TestBase; |
||||
|
using Volo.Abp.Autofac; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc; |
||||
|
|
||||
|
public class AbpAspNetCoreAsyncTestBase_Tests : AbpAspNetCoreAsyncTestBase<AbpAspNetCoreAsyncTestModule> |
||||
|
{ |
||||
|
[Fact] |
||||
|
public async Task Get_API_Response_Test() |
||||
|
{ |
||||
|
var result = await GetResponseAsStringAsync("/api"); |
||||
|
result.ShouldBe(await GetRequiredService<DataBaseService>().GetResponseAsync()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpAspNetCoreMvcModule), |
||||
|
typeof(AbpAspNetCoreTestBaseModule), |
||||
|
typeof(AbpAutofacModule) |
||||
|
)] |
||||
|
public class AbpAspNetCoreAsyncTestModule : AbpModule |
||||
|
{ |
||||
|
public override Task ConfigureServicesAsync(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddTransient<DataBaseService>(); |
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) |
||||
|
{ |
||||
|
var app = context.GetApplicationBuilder(); |
||||
|
|
||||
|
var dataBaseService = app.ApplicationServices.GetRequiredService<DataBaseService>(); |
||||
|
|
||||
|
var apiResponse = await dataBaseService.GetResponseAsync(); |
||||
|
app.Map("/api", _ => |
||||
|
{ |
||||
|
app.Run(async httpContext => |
||||
|
{ |
||||
|
await httpContext.Response.WriteAsync(apiResponse); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
app.UseRouting(); |
||||
|
app.UseConfiguredEndpoints(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class DataBaseService |
||||
|
{ |
||||
|
public Task<string> GetResponseAsync() |
||||
|
{ |
||||
|
return Task.FromResult("hello api!"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
using System.Globalization; |
||||
|
using System.Net; |
||||
|
using System.Net.Http; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Net.Http.Headers; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.TestBase; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore; |
||||
|
|
||||
|
public abstract class AbpAspNetCoreAsyncTestBase<TModule> : AbpAspNetCoreAsyncIntegratedTestBase<TModule>, IAsyncLifetime |
||||
|
where TModule : AbpModule |
||||
|
{ |
||||
|
protected virtual async Task<T> GetResponseAsObjectAsync<T>(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
||||
|
{ |
||||
|
var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); |
||||
|
return JsonSerializer.Deserialize<T>(strResponse, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<string> GetResponseAsStringAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK) |
||||
|
{ |
||||
|
using (var response = await GetResponseAsync(url, expectedStatusCode)) |
||||
|
{ |
||||
|
return await response.Content.ReadAsStringAsync(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<HttpResponseMessage> GetResponseAsync(string url, HttpStatusCode expectedStatusCode = HttpStatusCode.OK, bool xmlHttpRequest = false) |
||||
|
{ |
||||
|
using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, url)) |
||||
|
{ |
||||
|
requestMessage.Headers.Add("Accept-Language", CultureInfo.CurrentUICulture.Name); |
||||
|
if (xmlHttpRequest) |
||||
|
{ |
||||
|
requestMessage.Headers.Add(HeaderNames.XRequestedWith, "XMLHttpRequest"); |
||||
|
} |
||||
|
var response = await Client.SendAsync(requestMessage); |
||||
|
response.StatusCode.ShouldBe(expectedStatusCode); |
||||
|
return response; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,11 +1,13 @@ |
|||||
using Volo.Abp.DynamicProxy; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DynamicProxy; |
||||
|
|
||||
namespace Volo.Abp.Autofac.Interception; |
namespace Volo.Abp.Autofac.Interception; |
||||
|
|
||||
public class Autofac_Interception_Test : AbpInterceptionTestBase<AutofacTestModule> |
public class Autofac_Interception_Test : AbpInterceptionTestBase<AutofacTestModule> |
||||
{ |
{ |
||||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
protected override Task<Action<AbpApplicationCreationOptions>> SetAbpApplicationCreationOptionsAsync() |
||||
{ |
{ |
||||
options.UseAutofac(); |
return Task.FromResult<Action<AbpApplicationCreationOptions>>(options => options.UseAutofac()); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,18 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Blazor.Server.Tiered; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameBlazorModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Blazor.Server; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameBlazorModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameHttpApiHostModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameHttpApiHostModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameIdentityServerModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Web; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameWebModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Web; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameWebModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,12 +1,22 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
namespace MyCompanyName.MyProjectName; |
||||
|
|
||||
public class HelloWorldService : ITransientDependency |
public class HelloWorldService : ITransientDependency |
||||
{ |
{ |
||||
public void SayHello() |
public ILogger<HelloWorldService> Logger { get; set; } |
||||
|
|
||||
|
public HelloWorldService() |
||||
|
{ |
||||
|
Logger = NullLogger<HelloWorldService>.Instance; |
||||
|
} |
||||
|
|
||||
|
public Task SayHelloAsync() |
||||
{ |
{ |
||||
Console.WriteLine("\tHello World!"); |
Logger.LogInformation("Hello World!"); |
||||
|
return Task.CompletedTask; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,40 +1,46 @@ |
|||||
using System; |
using System.Threading; |
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
using Microsoft.Extensions.Hosting; |
using Microsoft.Extensions.Hosting; |
||||
|
using Serilog; |
||||
using Volo.Abp; |
using Volo.Abp; |
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
namespace MyCompanyName.MyProjectName; |
||||
|
|
||||
public class MyProjectNameHostedService : IHostedService |
public class MyProjectNameHostedService : IHostedService |
||||
{ |
{ |
||||
private readonly IAbpApplicationWithExternalServiceProvider _application; |
private IAbpApplicationWithInternalServiceProvider _abpApplication; |
||||
private readonly IServiceProvider _serviceProvider; |
|
||||
private readonly HelloWorldService _helloWorldService; |
private readonly IConfiguration _configuration; |
||||
|
private readonly IHostEnvironment _hostEnvironment; |
||||
public MyProjectNameHostedService( |
|
||||
IAbpApplicationWithExternalServiceProvider application, |
public MyProjectNameHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment) |
||||
IServiceProvider serviceProvider, |
|
||||
HelloWorldService helloWorldService) |
|
||||
{ |
{ |
||||
_application = application; |
_configuration = configuration; |
||||
_serviceProvider = serviceProvider; |
_hostEnvironment = hostEnvironment; |
||||
_helloWorldService = helloWorldService; |
|
||||
} |
} |
||||
|
|
||||
public Task StartAsync(CancellationToken cancellationToken) |
public async Task StartAsync(CancellationToken cancellationToken) |
||||
{ |
{ |
||||
_application.Initialize(_serviceProvider); |
_abpApplication = await AbpApplicationFactory.CreateAsync<MyProjectNameModule>(options => |
||||
|
{ |
||||
|
options.Services.ReplaceConfiguration(_configuration); |
||||
|
options.Services.AddSingleton(_hostEnvironment); |
||||
|
|
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); |
||||
|
}); |
||||
|
|
||||
_helloWorldService.SayHello(); |
await _abpApplication.InitializeAsync(); |
||||
|
|
||||
return Task.CompletedTask; |
var helloWorldService = _abpApplication.ServiceProvider.GetRequiredService<HelloWorldService>(); |
||||
|
|
||||
|
await helloWorldService.SayHelloAsync(); |
||||
} |
} |
||||
|
|
||||
public Task StopAsync(CancellationToken cancellationToken) |
public async Task StopAsync(CancellationToken cancellationToken) |
||||
{ |
{ |
||||
_application.Shutdown(); |
await _abpApplication.ShutdownAsync(); |
||||
|
|
||||
return Task.CompletedTask; |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,3 +1,3 @@ |
|||||
{ |
{ |
||||
|
"MySettingName": "MySettingValue" |
||||
} |
} |
||||
|
|||||
@ -1,18 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.Blazor.Server.Host; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameBlazorHostModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameHttpApiHostModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,20 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameIdentityServerModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameWebHostModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
using Microsoft.AspNetCore.Hosting; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
|
||||
|
|
||||
public class Startup |
|
||||
{ |
|
||||
public void ConfigureServices(IServiceCollection services) |
|
||||
{ |
|
||||
services.AddApplication<MyProjectNameWebUnifiedModule>(); |
|
||||
} |
|
||||
|
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
|
||||
{ |
|
||||
app.InitializeApplication(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +1,20 @@ |
|||||
using Volo.Abp.DependencyInjection; |
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace MyCompanyName.MyProjectName; |
namespace MyCompanyName.MyProjectName; |
||||
|
|
||||
public class HelloWorldService : ITransientDependency |
public class HelloWorldService : ITransientDependency |
||||
{ |
{ |
||||
|
public ILogger<HelloWorldService> Logger { get; set; } |
||||
|
|
||||
|
public HelloWorldService() |
||||
|
{ |
||||
|
Logger = NullLogger<HelloWorldService>.Instance; |
||||
|
} |
||||
public string SayHello() |
public string SayHello() |
||||
{ |
{ |
||||
return "\tHello world!"; |
Logger.LogInformation("Call SayHello"); |
||||
|
return "Hello world!"; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue