1.生产ABP框架基础服务,如下图所示
2.新建一个控制台程序,添加对Application项目引用。
3.新建一个模块类
using Abp.Events.Bus;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Castle.MicroKernel.Registration;
using com.f1bpm.Configuration;
using com.f1bpm.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
namespace com.f1bpm.Jobs
{
[DependsOn(typeof(f1bpmApplicationModule))]
[DependsOn(typeof(f1bpmEntityFrameworkModule))]
public class MyConsoleAppModule : AbpModule
{
private readonly IConfigurationRoot _appConfiguration;
public MyConsoleAppModule(f1bpmEntityFrameworkModule abpProjectNameEntityFrameworkModule)
{
abpProjectNameEntityFrameworkModule.SkipDbSeed = true;
_appConfiguration = AppConfigurations.Get(
typeof(MyConsoleAppModule).GetAssembly().GetDirectoryPathOrNull()
);
}
public override void PreInitialize()
{
Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString(
f1bpmConsts.ConnectionStringName
);
Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
Configuration.ReplaceService(
typeof(IEventBus),
() => IocManager.IocContainer.Register(
Component.For<IEventBus>().Instance(NullEventBus.Instance)
)
);
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(typeof(MyConsoleAppModule).GetAssembly());
}
}
}
4.通过IOC调用应用层或领域层服务方法
using (var bootstrapper = AbpBootstrapper.Create<MyConsoleAppModule>())
{
bootstrapper.IocManager.IocContainer
.AddFacility<LoggingFacility>(
f => f.UseAbpLog4Net().WithConfig("log4net.config")
);
bootstrapper.Initialize();
using (var caller = bootstrapper.IocManager.ResolveAsDisposable<EngineManager>())
{
caller.Object.NewStart(jsondata);
}
}