abpvnext 运行启动顺序

我的项目是github上基于abp创建的一个快速框架Abp Vnext Pro来生成的,可能会跟abp官方生成的项目结构稍稍有点区别,单基本上相同。

本文章只是为了记录abpvnext项目中类和方法的启动加载顺序。

  1. Program类

Main方法中调用 CreateHostBuilder(ASP.NET Core托管模型)方法

CreateHostBuilder中,会启动Startup构造。

  1. Startup类

由上一步的CreateHostBuilder启动Startup 构造;再执ConfigureServices方法。

ConfigureServices方法:其中调用了services.AddApplication<HttpApiHostModule>,HttpApiHostModule中注册加载了项目需要用的模块。

然后执行Configure()。

Configure:其中调用app.InitializeApplication,这是aspnetcore 中参数 Microsoft.AspNetCore.Builder.IApplicationBuilder执行对应用程序的初始加载。

我这里还有另外一个IHostApplicationLifetime lifetime 参数 用来执行一些预热注册

lifetime.ApplicationStopped.Register(ConfigurePreheat); 其中ConfigurePreheat为委托对象方法,里面包含自定义的需要预热的加载。

---------未完待续

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Abp框架提供了一些基本的数据访问方法,如GetAll, Get, Insert, Update, Delete等,它们可以满足大多数应用程序的需求。但是,如果需要执行复杂的SQL查询或操作,可以使用Dapper来执行原生SQL。Dapper是一个轻量级的ORM框架,可以在Abp应用程序中与Entity Framework Core一起使用。以下是一个使用Dapper执行原生SQL查询的示例: 1. 安装Dapper NuGet包 可以使用NuGet包管理器或在项目文件中手动添加以下条目来安装Dapper: ``` Install-Package Dapper ``` 2. 创建DapperRepository 我们可以创建一个名为DapperRepository的仓储类,它将使用Dapper执行原生SQL查询或操作。以下是一个简单的DapperRepository类的示例: ``` public class DapperRepository<TEntity> : IRepository<TEntity> where TEntity : class, IEntity<int> { private readonly IDbConnection _dbConnection; public DapperRepository(IDbConnection dbConnection) { _dbConnection = dbConnection; } public async Task<List<TEntity>> GetAllListAsync() { return (await _dbConnection.GetListAsync<TEntity>()).ToList(); } public async Task<TEntity> GetAsync(int id) { return await _dbConnection.GetAsync<TEntity>(id); } public async Task<TEntity> InsertAsync(TEntity entity) { entity.Id = await _dbConnection.InsertAsync(entity); return entity; } public async Task<TEntity> UpdateAsync(TEntity entity) { await _dbConnection.UpdateAsync(entity); return entity; } public async Task DeleteAsync(int id) { await _dbConnection.DeleteAsync<TEntity>(id); } public async Task<List<TEntity>> QueryAsync(string sql, object param = null) { return (await _dbConnection.QueryAsync<TEntity>(sql, param)).ToList(); } public async Task<TEntity> QueryFirstOrDefaultAsync(string sql, object param = null) { return await _dbConnection.QueryFirstOrDefaultAsync<TEntity>(sql, param); } } ``` 3. 注册DapperRepository 在应用程序的Startup.cs文件中,我们可以使用依赖注入将DapperRepository注册到容器中: ``` services.AddScoped(typeof(IRepository<>), typeof(DapperRepository<>)); ``` 4. 使用DapperRepository执行查询 现在我们可以在应用程序中使用DapperRepository来执行原生SQL查询或操作。以下是一个使用DapperRepository执行查询的示例: ``` public class MyService : IMyService { private readonly IRepository<MyEntity> _repository; public MyService(IRepository<MyEntity> repository) { _repository = repository; } public async Task<List<MyEntity>> GetEntitiesWithComplexQueryAsync() { string sql = "SELECT * FROM MyEntities WHERE MyProperty = @myParam"; var parameters = new { myParam = "someValue" }; return await _repository.QueryAsync(sql, parameters); } } ``` 在上面的示例中,我们使用DapperRepository执行了一个带有参数的原生SQL查询,并将结果作为MyEntity对象列表返回。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值