在線文檔:http://doc.yc-l.com/#/README
在線演示地址:http://yc.yc-l.com/#/login
源碼github:https://github.com/linbin524/yc.boilerplate
源碼gitee:https://gitee.com/linxuanming/yc.boilerplate
元磁之力框架技術群QQ:1060819005
視頻教程:
- 元磁之力框架開源初心和框架設計介紹(上): https://www.bilibili.com/video/BV1VM4y1G7hC/
- 元磁之力框架開源初心和框架設計介紹(下): https://www.bilibili.com/video/BV15h411s7w6/
- 元磁之力框架數據庫表和代碼生成使用教程實戰: https://www.bilibili.com/video/BV1oM4y137D5/
數據層ORM 設計
適配支持 Dapper和Freesql
數據層采用開發動態注入模式選擇對應的ORM,目前規划設計支持Dapper 和Freesql。
映射流程如下

dapper ORM
dapper 使用說明
統一設計IUnitOfWork 接口,默認實現sql 工作單元模式的DefaultUnitOfWork和簡單型 單表 Lambda模式的LambdaUnitOfWork。
PS:接入dapper 主要是為了原生sql的對接。性能效率高,缺點是沒有lambda 語法糖的舒服感。
類圖關系如下:

注入操作核心代碼
public class DapperAutofacModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterGeneric(typeof(RepositoryBase<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope().EnableInterfaceInterceptors()
.InterceptedBy(typeof(AopInterceptor));//這一步是倉儲注入的重要的點,允許攔截器
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
// builder.RegisterType<DefaultUnitOfWork>().As<IUnitOfWork>().WithParameter("dbConnectionString",dbConfig.DefaultDbConnectionString).AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired();
builder.RegisterType<DefaultUnitOfWork>().As<DapperFrameWork.IUnitOfWork>().AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired();
//builder.RegisterType<TenantIdentificationStrategy>().As<ITenantIdentificationStrategy>().AsImplementedInterfaces().InstancePerLifetimeScope().PropertiesAutowired();
}
}
FreeSql ORM
freeSql 使用介紹
通過設計 IFreeSqlRepository<TEntity, TKey>、 IFreeSqlRepository
PS:接入freesql 原因:在作者使用過的各種orm中,它的學習成本低、舒適度、便捷度都很棒,便於懶人模式。
類圖關系如下:

注入核心代碼
/// <summary>
/// FreeSql 注入模塊
/// </summary>
public class FreesqlAutofacModule : Autofac.Module
{
/// <summary>
/// FreeSql 注入模塊操作
/// </summary>
/// <param name="builder"></param>
protected override void Load(ContainerBuilder builder)
{
builder.RegisterGeneric(typeof(FreeSqlRepository<,>)).As(typeof(IFreeSqlRepository<,>)).InstancePerLifetimeScope().EnableInterfaceInterceptors()
.InterceptedBy(typeof(AopInterceptor));//freeSql 注入
builder.RegisterGeneric(typeof(FreeSqlRepository<>)).As(typeof(IFreeSqlRepository<>)).InstancePerLifetimeScope().EnableInterfaceInterceptors()
.InterceptedBy(typeof(AopInterceptor));//freeSql 注入
//這個自帶DI注入,也是可以的,反正后面都會被autofac接管
//services.AddScoped(typeof(IFreeSqlRepository<,>), typeof(FreeSqlRepository<,>));
//services.AddScoped(typeof(IFreeSqlRepository<>), typeof(FreeSqlRepository<>));
}
}
