Abp.Extension.Orm.Dapper(不再建议使用,推荐Dapper Integration)
thanks Abp.Dapper,Dapper,DapperExtensions
- DependsOn
[DependsOn(typeof(OrmDapperModule))]
public class AbpZeroTemplateWebCoreModule : AbpModule
- init database connectionString open file Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){
app.UseOrmDapper(connectionString);
}
- Use Repository
private readonly IDapperRepository<User, long> _useDapperRepository;
//1 use sql
var output = (await _useDapperRepository.QueryAsync<User>("select * from AbpUsers")).ToList();
//2 no sql
var output = (await _useDapperRepository.GetListAsync<User>()).ToList();
//3 use uow
using (var uow = _useDapperRepository.Begin())
{
var output = (await _useDapperRepository.QueryAsync<User>("select * from AbpUsers")).ToList();
uow.Dispose();
}
Abp.Extension.Background(推荐使用官方实现)
- 引用dll
Install-Package Abp.Extension.Background
- 添加任务类
public class TestTask : IHTask
{
public ILogger Logger { get; set; }
public TestTask()
{
Logger = IocManager.Instance.Resolve<ILogger>();
}
public void Run()
{
Logger.Debug("测试任务执行.............");
}
public string Cron()
{
return Hangfire.Cron.Minutely();
}
}
- 注册任务类
//依赖
[DependsOn(typeof(AbpBackgroundModule))]
//注册
public override void PostInitialize()
{
var queue = IocManager.Resolve<BackTaskQueue>();
queue.Add(typeof(TestTask).FullName, typeof(TestTask));
}
- Host项目startUp 启用hangfire
//a. ConfigureServices方法
services.AddHangfire(config =>
{
config.UseMemoryStorage();
});
//b.Configure方法
//app.UseHangfireDashboard("/hangfire", new DashboardOptions
// {
// Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
// });
app.UseHangfireServer();
//****
app.RunHangfireTask();