Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 lines
1.5 KiB

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Volo.Abp;
namespace MyCompanyName.MyProjectName;
public class MyProjectNameHostedService : IHostedService
{
private IAbpApplicationWithInternalServiceProvider _abpApplication;
private readonly IConfiguration _configuration;
private readonly IHostEnvironment _hostEnvironment;
public MyProjectNameHostedService(IConfiguration configuration, IHostEnvironment hostEnvironment)
{
_configuration = configuration;
_hostEnvironment = hostEnvironment;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
_abpApplication = await AbpApplicationFactory.CreateAsync<MyProjectNameModule>(options =>
{
options.Services.ReplaceConfiguration(_configuration);
options.Services.AddSingleton(_hostEnvironment);
options.UseAutofac();
options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog());
});
await _abpApplication.InitializeAsync();
var helloWorldService = _abpApplication.ServiceProvider.GetRequiredService<HelloWorldService>();
await helloWorldService.SayHelloAsync();
}
public async Task StopAsync(CancellationToken cancellationToken)
{
await _abpApplication.ShutdownAsync();
}
}