Skip to content

SmallShrimp/Abp.Extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abp.Extension.Orm.Dapper(不再建议使用,推荐Dapper Integration)

thanks Abp.Dapper,Dapper,DapperExtensions

how to use!

  1. DependsOn
[DependsOn(typeof(OrmDapperModule))]
public class AbpZeroTemplateWebCoreModule : AbpModule
  1. init database connectionString open file Startup.cs
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){
    	app.UseOrmDapper(connectionString);
    }
  1. 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(推荐使用官方实现

  1. 引用dll
Install-Package Abp.Extension.Background
  1. 添加任务类
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();
        }
    }
  1. 注册任务类
//依赖
[DependsOn(typeof(AbpBackgroundModule))]
//注册
public override void PostInitialize()
        {
            
            var queue = IocManager.Resolve<BackTaskQueue>();
            queue.Add(typeof(TestTask).FullName, typeof(TestTask));

        }
  1. 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();