修改框架

This commit is contained in:
橙子
2021-10-10 17:52:23 +08:00
parent cf062cadcd
commit ee14ab4d2b
11 changed files with 84 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.ApiMicroservice namespace Yi.Framework.ApiMicroservice
{ {
@@ -28,6 +29,9 @@ namespace Yi.Framework.ApiMicroservice
{ {
services.AddControllers(); services.AddControllers();
services.Configure<SqliteOptions>(this.Configuration.GetSection("SqliteConn"));
services.AddSwaggerGen(c => services.AddSwaggerGen(c =>
{ {
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Yi.Framework.ApiMicroservice", Version = "v1" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "Yi.Framework.ApiMicroservice", Version = "v1" });
@@ -48,8 +52,10 @@ namespace Yi.Framework.ApiMicroservice
app.UseRouting(); app.UseRouting();
app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapControllers(); endpoints.MapControllers();

View File

@@ -8,4 +8,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Yi.Common.IOCOptions namespace Yi.Framework.Common.IOCOptions
{ {
public class ElasticSearchOptions public class ElasticSearchOptions
{ {

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace CC.ElectronicCommerce.Common.IOCOptions namespace Yi.Framework.Common.IOCOptions
{ {
public class JWTTokenOptions public class JWTTokenOptions
{ {

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace CC.ElectronicCommerce.Common.IOCOptions namespace Yi.Framework.Common.IOCOptions
{ {
public class KafkaOptions public class KafkaOptions
{ {

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.IOCOptions
{
public class SqliteOptions
{
public string Url { get; set; }
}
}

View File

@@ -4,4 +4,8 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="QueueModel\" />
</ItemGroup>
</Project> </Project>

View File

@@ -11,9 +11,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.IO; using System.IO;
using CC.ElectronicCommerce.Common.IOCOptions; using Yi.Framework.Common.IOCOptions;
namespace CC.ElectronicCommerce.Core namespace Yi.Framework.Core
{ {
public class CacheClientDB : IDisposable public class CacheClientDB : IDisposable
{ {

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.IOCOptions;
namespace Yi.Framework.Model.Models
{
public class DataContext : DbContext
{
private readonly IOptionsMonitor<SqliteOptions> _optionsMonitor;
private readonly string _connStr;
public DataContext(IOptionsMonitor<SqliteOptions> optionsMonitor)
{
_optionsMonitor = optionsMonitor;
_connStr = _optionsMonitor.CurrentValue.Url;
}
public DataContext(string connstr)
{
_connStr = connstr;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite(_connStr);
}
}
//public virtual DbSet<TbBrand> TbBrand { get; set; }
}
}

View File

@@ -4,4 +4,16 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Search\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Common\Yi.Framework.Common.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -4,4 +4,8 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
</Project> </Project>