mirror of https://github.com/abpframework/abp.git
8 changed files with 107 additions and 0 deletions
@ -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; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"ConnectionStrings": { |
||||
|
"Default": "Server=localhost;Database=BackgroundJobsDemoApp;Trusted_Connection=True;MultipleActiveResultSets=true" |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue