mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
## v0.3.19
- 兼容 GetTableByEntity 有可能因为传入数组类型的错误; - 修复 UnitOfWork 事务创建逻辑 bug; - 增加 FreeSql.DbContext 扩展包; - 调整 UnitOfWork、DbContext 不提交时默认会回滚;
This commit is contained in:
26
FreeSql.DbContext/DependencyInjection.cs
Normal file
26
FreeSql.DbContext/DependencyInjection.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql {
|
||||
public static class DbContextDependencyInjection {
|
||||
|
||||
public static IServiceCollection AddFreeDbContext<TDbContext>(this IServiceCollection services, Action<DbContextOptionsBuilder> options) where TDbContext : DbContext {
|
||||
|
||||
services.AddScoped<TDbContext>(sp => {
|
||||
var ctx = Activator.CreateInstance<TDbContext>();
|
||||
|
||||
if (ctx._orm == null) {
|
||||
var builder = new DbContextOptionsBuilder();
|
||||
options(builder);
|
||||
ctx._orm = builder._fsql;
|
||||
}
|
||||
|
||||
return ctx;
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user