mirror of https://github.com/abpframework/abp.git
committed by
GitHub
47 changed files with 746 additions and 315 deletions
@ -0,0 +1,32 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace AbpConsoleDemo |
||||
|
{ |
||||
|
public class AppHostedService : IHostedService |
||||
|
{ |
||||
|
public Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<AppModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); //Autofac integration
|
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
//Resolve a service and use it
|
||||
|
var helloWorldService = application.ServiceProvider.GetService<HelloWorldService>(); |
||||
|
helloWorldService.SayHello(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
|
||||
|
return Task.CompletedTask; |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,28 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
|
|
||||
namespace AbpConsoleDemo |
namespace AbpConsoleDemo |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<AppModule>(options => |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
options.UseAutofac(); //Autofac integration
|
|
||||
})) |
|
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
//Resolve a service and use it
|
|
||||
var helloWorldService = |
|
||||
application.ServiceProvider.GetService<HelloWorldService>(); |
|
||||
helloWorldService.SayHello(); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<AppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Acme.BookStore.Data; |
||||
|
using Serilog; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.DbMigrator |
||||
|
{ |
||||
|
public class DbMigratorHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(c => c.AddSerilog()); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
await application |
||||
|
.ServiceProvider |
||||
|
.GetRequiredService<BookStoreDbMigrationService>() |
||||
|
.MigrateAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Acme.BookStore.Data; |
||||
|
using Serilog; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.DbMigrator |
||||
|
{ |
||||
|
public class DbMigratorHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(c => c.AddSerilog()); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
await application |
||||
|
.ServiceProvider |
||||
|
.GetRequiredService<BookStoreDbMigrationService>() |
||||
|
.MigrateAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.BookManagement |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookManagementConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace Acme.BookStore.BookManagement |
namespace Acme.BookStore.BookManagement |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<BookManagementConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using Acme.BookStore.Data; |
||||
|
using Serilog; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.DbMigrator |
||||
|
{ |
||||
|
public class DbMigratorHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreDbMigratorModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(c => c.AddSerilog()); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
await application |
||||
|
.ServiceProvider |
||||
|
.GetRequiredService<BookStoreDbMigrationService>() |
||||
|
.MigrateAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
namespace Acme.BookStore.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<BookStoreConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using DashboardDemo.Data; |
||||
|
using Serilog; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace DashboardDemo.DbMigrator |
||||
|
{ |
||||
|
public class DbMigratorHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<DashboardDemoDbMigratorModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(c => c.AddSerilog()); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
await application |
||||
|
.ServiceProvider |
||||
|
.GetRequiredService<DashboardDemoDbMigrationService>() |
||||
|
.MigrateAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace DashboardDemo.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<DashboardDemoConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace DashboardDemo.HttpApi.Client.ConsoleTestApp |
namespace DashboardDemo.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<DashboardDemoConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,33 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
using Serilog; |
||||
|
|
||||
|
namespace ConsoleClientDemo |
||||
|
{ |
||||
|
public class ConsoleClientDemoHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<ConsoleClientDemoModule>(options => |
||||
|
{ |
||||
|
options.Services.AddLogging(loggingBuilder => |
||||
|
{ |
||||
|
loggingBuilder.AddSerilog(dispose: true); |
||||
|
}); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using MyCompanyName.MyProjectName.Data; |
||||
|
using Serilog; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.DbMigrator |
||||
|
{ |
||||
|
public class DbMigratorHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<MyProjectNameDbMigratorModule>(options => |
||||
|
{ |
||||
|
options.UseAutofac(); |
||||
|
options.Services.AddLogging(c => c.AddSerilog()); |
||||
|
})) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
await application |
||||
|
.ServiceProvider |
||||
|
.GetRequiredService<MyProjectNameDbMigrationService>() |
||||
|
.MigrateAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp |
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,26 @@ |
|||||
|
using Microsoft.Extensions.Hosting; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp; |
||||
|
|
||||
|
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp |
||||
|
{ |
||||
|
public class ConsoleTestAppHostedService : IHostedService |
||||
|
{ |
||||
|
public async Task StartAsync(CancellationToken cancellationToken) |
||||
|
{ |
||||
|
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) |
||||
|
{ |
||||
|
application.Initialize(); |
||||
|
|
||||
|
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
||||
|
await demo.RunAsync(); |
||||
|
|
||||
|
application.Shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; |
||||
|
} |
||||
|
} |
||||
@ -1,24 +1,21 @@ |
|||||
using System; |
using System.Threading.Tasks; |
||||
using Microsoft.Extensions.DependencyInjection; |
using Microsoft.Extensions.DependencyInjection; |
||||
using Volo.Abp; |
using Microsoft.Extensions.Hosting; |
||||
using Volo.Abp.Threading; |
|
||||
|
|
||||
namespace MyCompanyName.MyProjectName |
namespace MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp |
||||
{ |
{ |
||||
class Program |
class Program |
||||
{ |
{ |
||||
static void Main(string[] args) |
static async Task Main(string[] args) |
||||
{ |
{ |
||||
using (var application = AbpApplicationFactory.Create<MyProjectNameConsoleApiClientModule>()) |
await CreateHostBuilder(args).RunConsoleAsync(); |
||||
{ |
|
||||
application.Initialize(); |
|
||||
|
|
||||
var demo = application.ServiceProvider.GetRequiredService<ClientDemoService>(); |
|
||||
AsyncHelper.RunSync(() => demo.RunAsync()); |
|
||||
|
|
||||
Console.WriteLine("Press ENTER to stop application..."); |
|
||||
Console.ReadLine(); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
public static IHostBuilder CreateHostBuilder(string[] args) => |
||||
|
Host.CreateDefaultBuilder(args) |
||||
|
.ConfigureServices((hostContext, services) => |
||||
|
{ |
||||
|
services.AddHostedService<ConsoleTestAppHostedService>(); |
||||
|
}); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue