feat: 添加sample示例

This commit is contained in:
陈淳
2024-01-10 17:26:40 +08:00
parent a3f7c1e867
commit 2c8d579668
43 changed files with 907 additions and 1 deletions

View File

@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
<ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore\Yi.Framework.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.SqlSugarCore\Yi.Framework.Bbs.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" />
<ProjectReference Include="..\Acme.BookStore.Domain\Acme.BookStore.Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Repositories\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,50 @@
using Acme.BookStore.Domain.Entities;
using Acme.BookStore.Domain.Shared.Enums;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Acme.BookStore.SqlSugarCore.DataSeeds
{
public class BookStoreDataSeed : IDataSeedContributor, ITransientDependency
{
private ISqlSugarRepository<BookAggregateRoot> _bookRepository;
private IGuidGenerator _guidGenerator;
public BookStoreDataSeed(ISqlSugarRepository<BookAggregateRoot> repository, IGuidGenerator guidGenerator)
{
_bookRepository = repository;
_guidGenerator = guidGenerator;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _bookRepository.IsAnyAsync(x => true))
{
await _bookRepository.InsertAsync(
new BookAggregateRoot
{
Name = "1984",
Type = BookTypeEnum.Dystopia,
PublishDate = new DateTime(1949, 6, 8),
Price = 19.84f
},
autoSave: true
);
await _bookRepository.InsertAsync(
new BookAggregateRoot
{
Name = "The Hitchhiker's Guide to the Galaxy",
Type = BookTypeEnum.ScienceFiction,
PublishDate = new DateTime(1995, 9, 27),
Price = 42.0f
},
autoSave: true
);
}
}
}
}

View File

@@ -0,0 +1,31 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using Acme.BookStore.Domain;
using Acme.BookStore.SqlSugarCore;
using Yi.Framework.Bbs.SqlSugarCore;
using Yi.Framework.Mapster;
using Yi.Framework.Rbac.SqlSugarCore;
using Yi.Framework.SqlSugarCore;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Acme.BookStore.SqlsugarCore
{
[DependsOn(
typeof(YiAbpDomainModule),
typeof(YiFrameworkRbacSqlSugarCoreModule),
typeof(YiFrameworkBbsSqlSugarCoreModule),
typeof(YiFrameworkMapsterModule),
typeof(YiFrameworkSqlSugarCoreModule)
)]
public class YiAbpSqlSugarCoreModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddYiDbContext<YiDbContext>();
//默认不开放可根据项目需要是否Db直接对外开放
//context.Services.AddTransient(x => x.GetRequiredService<ISqlSugarDbContext>().SqlSugarClient);
}
}
}

View File

@@ -0,0 +1,45 @@
using Microsoft.Extensions.Logging;
using SqlSugar;
using Volo.Abp.DependencyInjection;
using Yi.Framework.Rbac.SqlSugarCore;
namespace Acme.BookStore.SqlSugarCore
{
public class YiDbContext : YiRbacDbContext
{
public YiDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider)
{
}
protected override void CustomDataFilter()
{
base.CustomDataFilter();
}
protected override void DataExecuted(object oldValue, DataAfterModel entityInfo)
{
base.DataExecuted(oldValue, entityInfo);
}
protected override void DataExecuting(object oldValue, DataFilterModel entityInfo)
{
base.DataExecuting(oldValue, entityInfo);
}
protected override void OnLogExecuting(string sql, SugarParameter[] pars)
{
base.OnLogExecuting(sql, pars);
}
protected override void OnLogExecuted(string sql, SugarParameter[] pars)
{
base.OnLogExecuted(sql, pars);
}
protected override void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient)
{
base.OnSqlSugarClientConfig(sqlSugarClient);
}
}
}