Added sample app for the background jobs module

pull/395/head
Halil ibrahim Kalkan 7 years ago
parent ae647e7757
commit c21a321104

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.BackgroundJobs.DemoApp.Db
{
public class DemoAppDbContext : AbpDbContext<DemoAppDbContext>
{
public DemoAppDbContext(DbContextOptions<DemoAppDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ConfigureBackgroundJobs();
}
}
}

@ -0,0 +1,29 @@
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace Volo.Abp.BackgroundJobs.DemoApp.Db
{
public class DemoAppDbContextFactory : IDesignTimeDbContextFactory<DemoAppDbContext>
{
public DemoAppDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<DemoAppDbContext>()
.UseSqlServer(configuration.GetConnectionString("Default"));
return new DemoAppDbContext(builder.Options);
}
private static IConfigurationRoot BuildConfiguration()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false);
return builder.Build();
}
}
}

@ -0,0 +1,20 @@
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
{
public class SampleJobCreator : ITransientDependency
{
private readonly IBackgroundJobManager _backgroundJobManager;
public SampleJobCreator(IBackgroundJobManager backgroundJobManager)
{
_backgroundJobManager = backgroundJobManager;
}
public void CreateJobs()
{
_backgroundJobManager.Enqueue(new WriteToConsoleJobArgs { Value = "42" });
_backgroundJobManager.Enqueue(new WriteToConsoleJobArgs { Value = "43" });
}
}
}

@ -0,0 +1,13 @@
using System;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
{
public class WriteToConsoleJob : BackgroundJob<WriteToConsoleJobArgs>, ITransientDependency
{
public override void Execute(WriteToConsoleJobArgs args)
{
Console.WriteLine($"WriteToConsoleJob: {args.Value}");
}
}
}

@ -0,0 +1,7 @@
namespace Volo.Abp.BackgroundJobs.DemoApp.Jobs
{
public class WriteToConsoleJobArgs
{
public string Value { get; set; }
}
}

@ -1,4 +1,6 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BackgroundJobs.DemoApp.Jobs;
namespace Volo.Abp.BackgroundJobs.DemoApp
{
@ -13,6 +15,11 @@ namespace Volo.Abp.BackgroundJobs.DemoApp
{
application.Initialize();
application
.ServiceProvider
.GetRequiredService<SampleJobCreator>()
.CreateJobs();
Console.WriteLine("Press ENTER to stop the application..!");
Console.ReadLine();
}

@ -6,8 +6,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.BackgroundJobs.EntityFrameworkCore\Volo.Abp.BackgroundJobs.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore.SqlServer\Volo.Abp.EntityFrameworkCore.SqlServer.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
Loading…
Cancel
Save