diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/AutoIocAddExtensions.cs b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/AutoIocAddExtensions.cs
index 6ac5f84a..db06ece0 100644
--- a/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/AutoIocAddExtensions.cs
+++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Microsoft/Extensions/DependencyInjection/AutoIocAddExtensions.cs
@@ -19,6 +19,21 @@ namespace Microsoft.Extensions.DependencyInjection
}
return services;
}
+
+ ///
+ /// 扫描全部
+ ///
+ ///
+ ///
+ public static IServiceCollection AddAutoIocServer(this IServiceCollection services)
+ {
+ var assemblys= AppDomain.CurrentDomain.GetAssemblies();
+ foreach (var a in assemblys)
+ {
+ RegIoc(services, a);
+ }
+ return services;
+ }
private static void RegIoc(IServiceCollection services, Assembly assembly)
{
foreach (var type in assembly.GetTypes())
@@ -27,13 +42,14 @@ namespace Microsoft.Extensions.DependencyInjection
var serviceAttribute = type.GetCustomAttribute();
if (serviceAttribute is not null)
{
+ //泛型类需要单独进行处理
//情况1:使用自定义[AppService(ServiceType = typeof(注册抽象或者接口))],手动去注册,放type即可
var serviceType = serviceAttribute.ServiceType;
//情况2 自动去找接口,如果存在就是接口,如果不存在就是本身
if (serviceType == null)
{
//获取最靠近的接口
- var firstInter = type.GetInterfaces().FirstOrDefault();
+ var firstInter = type .GetInterfaces().LastOrDefault();
if (firstInter is null)
{
serviceType = type;
diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj
index 7aece253..d711e643 100644
--- a/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj
+++ b/src/Yi.Framework/Yi.Framework.AspNetCore/Yi.Framework.AspNetCore.csproj
@@ -16,4 +16,8 @@
+
+
+
+
diff --git a/src/Yi.Framework/Yi.Framework.AspNetCore/YiFrameworkAspNetCoreModule.cs b/src/Yi.Framework/Yi.Framework.AspNetCore/YiFrameworkAspNetCoreModule.cs
new file mode 100644
index 00000000..e541aec0
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.AspNetCore/YiFrameworkAspNetCoreModule.cs
@@ -0,0 +1,23 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using StartupModules;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.AspNetCore
+{
+ internal class YiFrameworkAspNetCoreModule : IStartupModule
+ {
+ public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
+ {
+ }
+
+ public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
+ {
+ services.AddAutoIocServer();
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Class1.cs b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Class1.cs
deleted file mode 100644
index 006cc701..00000000
--- a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Class1.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Yi.Framework.Caching.MemoryCache
-{
- public class Class1
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/MemoryCacheClient.cs b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/MemoryCacheClient.cs
new file mode 100644
index 00000000..1338c729
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/MemoryCacheClient.cs
@@ -0,0 +1,41 @@
+using Microsoft.Extensions.Caching.Memory;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Caching.MemoryCache
+{
+ public class MemoryCacheClient : CacheInvoker
+ {
+ private IMemoryCache _client;
+ public MemoryCacheClient()
+ {
+ _client = new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions());
+ }
+ public override bool Exits(string key)
+ {
+ return _client.TryGetValue(key, out var _);
+ }
+ public override T Get(string key)
+ {
+ return _client.Get(key);
+ }
+ public override bool Set(string key, T item)
+ {
+ return _client.Set(key, item) is not null;
+ }
+
+ public override bool Set(string key, T item, TimeSpan time)
+ {
+ return _client.Set(key, item, time) is not null;
+ }
+
+ public override long Del(string key)
+ {
+ _client.Remove(key);
+ return 1;
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Properties/launchSettings.json b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Properties/launchSettings.json
deleted file mode 100644
index bb9c6366..00000000
--- a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Properties/launchSettings.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "profiles": {
- "Yi.Framework.Caching.MemoryCache": {
- "commandName": "Project",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- },
- "applicationUrl": "https://localhost:53045;http://localhost:53046"
- }
- }
-}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Yi.Framework.Caching.MemoryCache.csproj b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Yi.Framework.Caching.MemoryCache.csproj
index 132c02c5..829e6465 100644
--- a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Yi.Framework.Caching.MemoryCache.csproj
+++ b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/Yi.Framework.Caching.MemoryCache.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -6,4 +6,13 @@
enable
+
+
+
+
+
+
+
+
+
diff --git a/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs
new file mode 100644
index 00000000..4656bdf5
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching.MemoryCache/YiFrameworkCachingMemoryCacheModule.cs
@@ -0,0 +1,25 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using StartupModules;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Caching.MemoryCache;
+using Yi.Framework.Caching;
+
+namespace Yi.Framework.Ddd
+{
+ public class YiFrameworkCachingMemoryCacheModule:IStartupModule
+ {
+ public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
+ {
+ }
+
+ public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
+ {
+ services.AddSingleton();
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching.Redis/Class1.cs b/src/Yi.Framework/Yi.Framework.Caching.Redis/Class1.cs
deleted file mode 100644
index 117b97a5..00000000
--- a/src/Yi.Framework/Yi.Framework.Caching.Redis/Class1.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Yi.Framework.Caching.Redis
-{
- public class Class1
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Caching.Redis/RedisCacheClient.cs b/src/Yi.Framework/Yi.Framework.Caching.Redis/RedisCacheClient.cs
new file mode 100644
index 00000000..23ad98dd
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching.Redis/RedisCacheClient.cs
@@ -0,0 +1,165 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using StartupModules;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Caching;
+using Microsoft.Extensions.Options;
+using Yi.Framework.Caching.Redis;
+using static CSRedis.CSRedisClient;
+using CSRedis;
+
+namespace Yi.Framework.Caching.Redis
+{
+ public class RedisCacheClient : CacheInvoker
+ {
+ private readonly CachingConnOptions _RedisOptions;
+
+ private CSRedisClient _client;
+
+ public RedisCacheClient(IOptionsMonitor redisConnOptions)
+ {
+ this._RedisOptions = redisConnOptions.CurrentValue;
+ _client = new CSRedisClient($"{_RedisOptions.Host}:{_RedisOptions.Prot},password={_RedisOptions.Password},defaultDatabase ={_RedisOptions.DB}");
+ }
+ public override bool Exits(string key)
+ {
+ return _client.Exists(key);
+ }
+ public override T Get(string key)
+ {
+ return _client.Get(key);
+ }
+
+ public override bool Set(string key, T data, TimeSpan time)
+ {
+ return _client.Set(key, data, time);
+ }
+
+ public override bool Set(string key, T data)
+ {
+ return _client.Set(key, data);
+ }
+
+ public override long Del(string key)
+ {
+ return _client.Del(key);
+ }
+
+ public override bool HSet(string key, string fieId, object data)
+ {
+ return _client.HSet(key, fieId, data);
+ }
+
+ public override bool HSet(string key, string fieId, object data, TimeSpan time)
+ {
+ var res = _client.HSet(key, fieId, data);
+ var res2 = _client.Expire(key, time);
+ return res && res2;
+ }
+
+ public override T HGet(string key, string field)
+ {
+ return _client.HGet(key, field);
+ }
+
+
+ public override long HDel(string key, params string[] par)
+ {
+ return _client.HDel(key, par);
+ }
+
+ public override long HLen(string key)
+ {
+ return _client.HLen(key);
+ }
+
+ public override Dictionary HGetAll(string key)
+ {
+ return _client.HGetAll(key);
+ }
+
+ ///
+ /// 简单发布
+ ///
+ ///
+ ///
+ ///
+ public override long Publish(string channel, string message)
+ {
+ return _client.Publish(channel, message);
+ }
+
+ ///
+ /// 简单订阅:广播,无持久化,需要Publish写入队列
+ ///
+ ///
+ ///
+ public override SubscribeObject Subscribe(params (string, Action)[] channels)
+ {
+ return _client.Subscribe(channels);
+ }
+
+ ///
+ /// 多端争抢模式订阅,需要Lpush写入队列
+ ///
+ ///
+ ///
+ ///
+ public override SubscribeListObject SubscribeList(string listKey, Action onMessage)
+ {
+ return _client.SubscribeList(listKey, onMessage);
+ }
+
+ ///
+ /// 多端非争抢模式订阅,需要Lpush写入队列
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override SubscribeListBroadcastObject SubscribeListBroadcast(string listKey, string clientId, Action onMessage)
+ {
+ return _client.SubscribeListBroadcast(listKey, clientId, onMessage);
+ }
+
+ public override bool LSet(string key, long index, object value)
+ {
+ return _client.LSet(key, index, value);
+ }
+
+
+
+ ///
+ /// 列表插入头部
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override long LPush(string key, params T[] value)
+ {
+ return _client.LPush(key, value);
+ }
+
+ ///
+ /// 列表弹出头部
+ ///
+ ///
+ ///
+ ///
+ public override T LPop(string key)
+ {
+ return _client.LPop(key);
+ }
+
+ public override string[] Keys(string pattern)
+ {
+ return _client.Keys(pattern);
+ }
+
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching.Redis/Yi.Framework.Caching.Redis.csproj b/src/Yi.Framework/Yi.Framework.Caching.Redis/Yi.Framework.Caching.Redis.csproj
index 132c02c5..19bf78cb 100644
--- a/src/Yi.Framework/Yi.Framework.Caching.Redis/Yi.Framework.Caching.Redis.csproj
+++ b/src/Yi.Framework/Yi.Framework.Caching.Redis/Yi.Framework.Caching.Redis.csproj
@@ -6,4 +6,13 @@
enable
+
+
+
+
+
+
+
+
+
diff --git a/src/Yi.Framework/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs b/src/Yi.Framework/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs
new file mode 100644
index 00000000..fa1881c6
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching.Redis/YiFrameworkCachingRedisModule.cs
@@ -0,0 +1,22 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using StartupModules;
+using Yi.Framework.Core.Configuration;
+
+namespace Yi.Framework.Caching.Redis
+{
+
+ public class YiFrameworkCachingRedisModule : IStartupModule
+ {
+ public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
+ {
+ }
+
+ public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
+ {
+ services.Configure(Appsettings.appConfiguration("CachingConnOptions"));
+ services.AddSingleton();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Caching/CacheInvoker.cs b/src/Yi.Framework/Yi.Framework.Caching/CacheInvoker.cs
new file mode 100644
index 00000000..c5ee8ea2
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching/CacheInvoker.cs
@@ -0,0 +1,116 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Caching
+{
+ public abstract class CacheInvoker
+ {
+
+ public virtual bool Exits(string key)
+ {
+ throw new NotImplementedException();
+ }
+ public virtual T Get(string key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual bool Set(string key, T data, TimeSpan time)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual bool Set(string key, T data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual long Del(string key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual bool HSet(string key, string fieId, object data)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual bool HSet(string key, string fieId, object data, TimeSpan time)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual T HGet(string key, string field)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public virtual long HDel(string key, params string[] par)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual long HLen(string key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual Dictionary HGetAll(string key)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// 简单发布
+ ///
+ ///
+ ///
+ ///
+ public virtual long Publish(string channel, string message)
+ {
+ throw new NotImplementedException();
+ }
+
+
+
+
+ public virtual bool LSet(string key, long index, object value)
+ {
+ throw new NotImplementedException();
+ }
+
+
+
+ ///
+ /// 列表插入头部
+ ///
+ ///
+ ///
+ ///
+ ///
+ public virtual long LPush(string key, params T[] value)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// 列表弹出头部
+ ///
+ ///
+ ///
+ ///
+ public virtual T LPop(string key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual string[] Keys(string pattern)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching/CachingConnOptions.cs b/src/Yi.Framework/Yi.Framework.Caching/CachingConnOptions.cs
new file mode 100644
index 00000000..39f9ed92
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Caching/CachingConnOptions.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Caching
+{
+ public class CachingConnOptions
+ {
+ public string? Host { get; set; }
+ public int DB { get; set; } = 0;
+ public int Prot { get; set; }
+ public string? Password { get; set; }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Caching/Class1.cs b/src/Yi.Framework/Yi.Framework.Caching/Class1.cs
deleted file mode 100644
index 9613382b..00000000
--- a/src/Yi.Framework/Yi.Framework.Caching/Class1.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Yi.Framework.Caching
-{
- public class Class1
- {
-
- }
-}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs
new file mode 100644
index 00000000..da569fc5
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Extensions/AutoMapperExtensions.cs
@@ -0,0 +1,33 @@
+
+using AutoMapper;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Core.Helper;
+
+namespace Yi.Framework.Autofac.Extensions
+{
+ public static class AutoMapperExtensions
+ {
+ public static IServiceCollection AddAutoMapperService(this IServiceCollection services)
+ {
+ //这里会通过反射,扫码全部程序集获取继承Profile的类
+ var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
+
+ var profileList = new List();
+ assemblies.ForEach(a =>
+ {
+ if (a.FullName is not null)
+ {
+ profileList.AddRange(AssemblyHelper.GetClassByBaseClassesAndInterfaces(a.FullName, typeof(Profile)));
+ }
+
+ });
+ services.AddAutoMapper(profileList.ToArray());
+ return services;
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj
new file mode 100644
index 00000000..e7101d08
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/Yi.Framework.Core.AutoMapper.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/src/Yi.Framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs
new file mode 100644
index 00000000..8a222cf7
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core.AutoMapper/YiFrameworkCoreAutoMapperModule.cs
@@ -0,0 +1,21 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using StartupModules;
+using Yi.Framework.Autofac.Extensions;
+
+namespace Yi.Framework.Core.AutoMapper
+{
+ public class YiFrameworkCoreAutoMapperModule : IStartupModule
+ {
+ public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
+ {
+ }
+
+ public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
+ {
+
+ //添加全局自动mapper
+ services.AddAutoMapperService();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Yi.Framework/Yi.Framework.Autofac/Extensions/AutoFacExtensions.cs b/src/Yi.Framework/Yi.Framework.Core.Autofac/Extensions/AutoFacExtensions.cs
similarity index 100%
rename from src/Yi.Framework/Yi.Framework.Autofac/Extensions/AutoFacExtensions.cs
rename to src/Yi.Framework/Yi.Framework.Core.Autofac/Extensions/AutoFacExtensions.cs
diff --git a/src/Yi.Framework/Yi.Framework.Autofac/Properties/launchSettings.json b/src/Yi.Framework/Yi.Framework.Core.Autofac/Properties/launchSettings.json
similarity index 100%
rename from src/Yi.Framework/Yi.Framework.Autofac/Properties/launchSettings.json
rename to src/Yi.Framework/Yi.Framework.Core.Autofac/Properties/launchSettings.json
diff --git a/src/Yi.Framework/Yi.Framework.Autofac/Yi.Framework.Autofac.csproj b/src/Yi.Framework/Yi.Framework.Core.Autofac/Yi.Framework.Core.Autofac.csproj
similarity index 100%
rename from src/Yi.Framework/Yi.Framework.Autofac/Yi.Framework.Autofac.csproj
rename to src/Yi.Framework/Yi.Framework.Core.Autofac/Yi.Framework.Core.Autofac.csproj
diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs
index 00ff1997..4cacd2ac 100644
--- a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs
+++ b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Repository/SqlsugarRepository.cs
@@ -9,7 +9,7 @@ using Yi.Framework.Ddd.Repository;
namespace Yi.Framework.Core.Sqlsugar.Repository
{
- [AppService]
+ [AppService(ServiceType =typeof(IRepository<>))]
public class SqlsugarRepository : SimpleClient, IRepository where T : class, new()
{
public SqlsugarRepository(ISqlSugarClient context) : base(context)
diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Yi.Framework.Core.Sqlsugar.csproj b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Yi.Framework.Core.Sqlsugar.csproj
index e5d3cce8..d0550922 100644
--- a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Yi.Framework.Core.Sqlsugar.csproj
+++ b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/Yi.Framework.Core.Sqlsugar.csproj
@@ -15,4 +15,8 @@
+
+
+
+
diff --git a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs
index 1e4d47f0..5d171e17 100644
--- a/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs
+++ b/src/Yi.Framework/Yi.Framework.Core.Sqlsugar/YiFrameworkCoreSqlsugarModule.cs
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
+using Yi.Framework.Core.Configuration;
+using Yi.Framework.Core.Options;
using Yi.Framework.Core.Sqlsugar.Extensions;
using Yi.Framework.Core.Sqlsugar.Repository;
using Yi.Framework.Ddd;
@@ -17,6 +19,7 @@ namespace Yi.Framework.Core.Sqlsugar
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddTransient(typeof(IRepository<>), typeof(SqlsugarRepository<>));
+ services.Configure(Appsettings.appConfiguration("DbConn"));
services.AddSqlsugarServer();
}
}
diff --git a/src/Yi.Framework/Yi.Framework.Core/CurrentUser/CurrentUser.cs b/src/Yi.Framework/Yi.Framework.Core/CurrentUser/CurrentUser.cs
new file mode 100644
index 00000000..cc24158f
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core/CurrentUser/CurrentUser.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Core.CurrentUser
+{
+ public class CurrentUser : ICurrentUser
+ {
+ public bool IsAuthenticated { get; set; }
+
+ public long Id { get; set; }
+
+ public string UserName { get; set; } = string.Empty;
+
+ public Guid? TenantId { get; set; }
+
+ public string Email { get; set; } = string.Empty;
+
+ public bool EmailVerified { get; set; }
+
+ public string PhoneNumber { get; set; } = string.Empty;
+
+ public bool PhoneNumberVerified { get; set; }
+
+ public string[]? Roles { get; set; }
+
+ public string[]? Permission { get; set; }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core/CurrentUser/ICurrentUser.cs b/src/Yi.Framework/Yi.Framework.Core/CurrentUser/ICurrentUser.cs
new file mode 100644
index 00000000..609a296e
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core/CurrentUser/ICurrentUser.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Core.CurrentUser
+{
+ public interface ICurrentUser
+ {
+ public bool IsAuthenticated { get; set; }
+ public long Id { get; set; }
+
+ public string UserName { get; set; }
+
+ public Guid? TenantId { get; set; }
+
+ public string Email { get; set; }
+
+ public bool EmailVerified { get; set; }
+
+ public string PhoneNumber { get; set; }
+
+ public bool PhoneNumberVerified { get; set; }
+
+ public string[]? Roles { get; set; }
+
+ public string[]? Permission { get; set; }
+
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core/Extensions/CurrentUserExtensions.cs b/src/Yi.Framework/Yi.Framework.Core/Extensions/CurrentUserExtensions.cs
new file mode 100644
index 00000000..18a17b89
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core/Extensions/CurrentUserExtensions.cs
@@ -0,0 +1,78 @@
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Claims;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Core.CurrentUser;
+
+namespace Yi.Framework.Core.Extensions
+{
+ public static class CurrentUserExtensions
+ {
+ public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
+ {
+ return services.AddScoped();
+ }
+
+
+ public static IApplicationBuilder UseCurrentUserServer(this IApplicationBuilder app)
+ {
+ return app.UseMiddleware();
+ }
+ }
+
+
+ public class CurrentUserMiddleware
+ {
+
+ private readonly RequestDelegate _next;
+ private ILogger _logger;
+ public CurrentUserMiddleware(RequestDelegate next, ILogger logger)
+ {
+ _next = next;
+ _logger = logger;
+ }
+
+ public async Task Invoke(HttpContext context, ICurrentUser _currentUser)
+ {
+ var authenticateContext = await context.AuthenticateAsync();
+ if (authenticateContext.Principal is null)
+ {
+ _currentUser.IsAuthenticated = false;
+ await _next(context);
+ return;
+ }
+ var claims = authenticateContext.Principal.Claims;
+ //通过鉴权之后,开始赋值
+ _currentUser.IsAuthenticated = true;
+ _currentUser.Id = claims.GetClaim(JwtRegisteredClaimNames.Sid) is null ? 0 : Convert.ToInt64(claims.GetClaim(JwtRegisteredClaimNames.Sid));
+ _currentUser.UserName = claims.GetClaim(SystemConst.UserName) ?? "";
+ _currentUser.Permission = claims.GetClaims(SystemConst.PermissionClaim);
+ _currentUser.TenantId = claims.GetClaim(SystemConst.TenantId) is null ? null : Guid.Parse(claims.GetClaim(SystemConst.TenantId)!);
+ await _next(context);
+
+ }
+
+
+
+ }
+
+ public static class ClaimExtension
+ {
+ public static string? GetClaim(this IEnumerable claims, string type)
+ {
+ return claims.Where(c => c.Type == type).Select(c => c.Value).FirstOrDefault();
+ }
+
+ public static string[]? GetClaims(this IEnumerable claims, string type)
+ {
+ return claims.Where(c => c.Type == type).Select(c => c.Value).ToArray();
+ }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs b/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs
new file mode 100644
index 00000000..64491a84
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core/Helper/AssemblyHelper.cs
@@ -0,0 +1,65 @@
+using AutoMapper.Internal;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Core.Helper
+{
+ public static class AssemblyHelper
+ {
+
+ public static List GetReferanceAssemblies(this AppDomain domain)
+ {
+ var list = new List();
+ domain.GetAssemblies().ToList().ForEach(i =>
+ {
+ GetReferanceAssemblies(i, list);
+ });
+ return list;
+ }
+ private static void GetReferanceAssemblies(Assembly assembly, List list)
+ {
+ assembly.GetReferencedAssemblies().ToList().ForEach(i =>
+ {
+ var ass = Assembly.Load(i);
+ if (!list.Contains(ass))
+ {
+ list.Add(ass);
+ GetReferanceAssemblies(ass, list);
+ }
+ });
+ }
+
+ public static List GetClass(string assemblyFile, string? className = null, string? spaceName = null)
+ {
+ Assembly assembly = Assembly.Load(assemblyFile);
+ return assembly.GetTypes().Where(m => m.IsClass
+ && className == null ? true : m.Name == className
+ && spaceName == null ? true : m.Namespace == spaceName
+ ).ToList();
+ }
+
+ public static List GetClassByBaseClassesAndInterfaces(string assemblyFile, Type type)
+ {
+ Assembly assembly = Assembly.Load(assemblyFile);
+
+ List resList = new List();
+
+ List typeList = assembly.GetTypes().Where(m => m.IsClass).ToList();
+ foreach (var t in typeList)
+ {
+ var data = t.BaseClassesAndInterfaces();
+ if (data.Contains(type))
+ {
+ resList.Add(t);
+ }
+
+ }
+ return resList;
+ }
+
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core/Options/SqlConnOptions.cs b/src/Yi.Framework/Yi.Framework.Core/Options/SqlConnOptions.cs
new file mode 100644
index 00000000..8bc0a560
--- /dev/null
+++ b/src/Yi.Framework/Yi.Framework.Core/Options/SqlConnOptions.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Core.Options
+{
+ public class SqlConnOptions
+ {
+ public string WriteUrl { get; set; } = string.Empty;
+ public List? ReadUrl { get; set; }
+ }
+}
diff --git a/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj b/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj
index 53c43437..29cfd714 100644
--- a/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj
+++ b/src/Yi.Framework/Yi.Framework.Core/Yi.Framework.Core.csproj
@@ -7,11 +7,11 @@
-
+
diff --git a/src/Yi.Framework/Yi.Framework.Core/YiFrameworkCoreModule.cs b/src/Yi.Framework/Yi.Framework.Core/YiFrameworkCoreModule.cs
index a85f6c3e..8ef8755c 100644
--- a/src/Yi.Framework/Yi.Framework.Core/YiFrameworkCoreModule.cs
+++ b/src/Yi.Framework/Yi.Framework.Core/YiFrameworkCoreModule.cs
@@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Configuration;
+using Yi.Framework.Core.Extensions;
using Yi.Framework.Core.Model;
namespace Yi.Framework.Core
@@ -25,6 +26,7 @@ namespace Yi.Framework.Core
//添加全局配置类
services.AddSingleton(new Appsettings(context.Configuration));
+
//全局日志
GobalLogModel.SqlLogEnable = Appsettings.appBool("SqlLog_Enable");
GobalLogModel.LoginCodeEnable = Appsettings.appBool("LoginCode_Enable");
diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj
index e7101d08..f9a08c82 100644
--- a/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj
+++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/Yi.Framework.Ddd.csproj
@@ -7,6 +7,7 @@
+
diff --git a/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkDddModule.cs b/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkDddModule.cs
index 68681aca..3de4b32e 100644
--- a/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkDddModule.cs
+++ b/src/Yi.Framework/Yi.Framework.Ddd.Application/YiFrameworkDddModule.cs
@@ -17,6 +17,7 @@ namespace Yi.Framework.Ddd
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
+
}
}
}
diff --git a/src/Yi.Framework/Yi.Framework.Web/Program.cs b/src/Yi.Framework/Yi.Framework.Web/Program.cs
index c7c4edab..2e65aa22 100644
--- a/src/Yi.Framework/Yi.Framework.Web/Program.cs
+++ b/src/Yi.Framework/Yi.Framework.Web/Program.cs
@@ -1,8 +1,11 @@
using AspNetCore.Microsoft.AspNetCore.Builder;
using Panda.DynamicWebApi;
+using System.Reflection;
using Yi.Framework.Application;
+using Yi.Framework.Autofac.Extensions;
using Yi.Framework.Core;
+using Yi.Framework.Core.AutoMapper;
using Yi.Framework.Core.Extensions;
using Yi.Framework.Core.Sqlsugar;
using Yi.Framework.Core.Sqlsugar.Repository;
@@ -12,19 +15,25 @@ using Yi.Framework.Web;
var builder = WebApplication.CreateBuilder(args);
+builder.WebHost.UseUrls(builder.Configuration.GetValue("StartUrl"));
+
+//ģ
builder.UseYiModules(
typeof(YiFrameworkCoreModule).Assembly,
+ typeof(YiFrameworkCoreAutoMapperModule).Assembly,
typeof(YiFrameworkDddModule).Assembly,
typeof(YiFrameworkCoreSqlsugarModule).Assembly
);
+
+//ʹautofac
+builder.Host.UseAutoFacServerProviderFactory();
+
+//ӿ붯̬api
builder.Services.AddControllers();
builder.Services.AddDynamicWebApi();
-
-builder.Services.AddEndpointsApiExplorer();
-
+//swagger
builder.Services.AddSwaggerServer();
-//builder.Services.AddAutoIocServer("Yi.Framework.Core.Sqlsugar");
var app = builder.Build();
diff --git a/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj b/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj
index 5023d2fe..76343b14 100644
--- a/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj
+++ b/src/Yi.Framework/Yi.Framework.Web/Yi.Framework.Web.csproj
@@ -9,6 +9,8 @@
+
+
diff --git a/src/Yi.Framework/Yi.Framework.Web/appsettings.json b/src/Yi.Framework/Yi.Framework.Web/appsettings.json
index 504143d5..5489a7bf 100644
--- a/src/Yi.Framework/Yi.Framework.Web/appsettings.json
+++ b/src/Yi.Framework/Yi.Framework.Web/appsettings.json
@@ -7,6 +7,8 @@
},
"AllowedHosts": "*",
+ //程序启动地址,*代表全部网口
+ "StartUrl": "http://*:19002",
//数据库列表
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ],
diff --git a/src/Yi.Framework/Yi.Framework.sln b/src/Yi.Framework/Yi.Framework.sln
index b59030ea..350aff8c 100644
--- a/src/Yi.Framework/Yi.Framework.sln
+++ b/src/Yi.Framework/Yi.Framework.sln
@@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.BackgroundJobs
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Ddd", "Yi.Framework.Ddd.Application\Yi.Framework.Ddd.csproj", "{949F35A7-36E4-4080-9940-24BE52532078}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Autofac", "Yi.Framework.Autofac\Yi.Framework.Autofac.csproj", "{63BA134E-9D23-4EB8-87E4-B45B33D954F5}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Core.Autofac", "Yi.Framework.Core.Autofac\Yi.Framework.Core.Autofac.csproj", "{63BA134E-9D23-4EB8-87E4-B45B33D954F5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.AspNetCore", "Yi.Framework.AspNetCore\Yi.Framework.AspNetCore.csproj", "{2F5E5843-14FB-48F1-AEB0-B9FFE103B972}"
EndProject
@@ -41,7 +41,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Caching.Memory
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Uow", "Yi.Framework.Uow\Yi.Framework.Uow.csproj", "{3D83BE69-71BB-43BE-B3F1-A532215561CD}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Core.Sqlsugar", "Yi.Framework.Core.Sqlsugar\Yi.Framework.Core.Sqlsugar.csproj", "{58F4071D-66B7-4839-A247-79AF0E4E1C8E}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.Core.Sqlsugar", "Yi.Framework.Core.Sqlsugar\Yi.Framework.Core.Sqlsugar.csproj", "{58F4071D-66B7-4839-A247-79AF0E4E1C8E}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.Core.AutoMapper", "Yi.Framework.Core.AutoMapper\Yi.Framework.Core.AutoMapper.csproj", "{DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -117,6 +119,10 @@ Global
{58F4071D-66B7-4839-A247-79AF0E4E1C8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58F4071D-66B7-4839-A247-79AF0E4E1C8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58F4071D-66B7-4839-A247-79AF0E4E1C8E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -139,6 +145,7 @@ Global
{67CF07AB-2A72-4B36-A3A5-4CEB82B7C43C} = {EEF5F221-0E32-4A3D-B647-B4B5E7305806}
{3D83BE69-71BB-43BE-B3F1-A532215561CD} = {5F2B846D-96CE-400A-878E-220498F4EE31}
{58F4071D-66B7-4839-A247-79AF0E4E1C8E} = {5F2B846D-96CE-400A-878E-220498F4EE31}
+ {DFD34702-2EF6-4ECC-AE6E-9A1A3885BD26} = {5F2B846D-96CE-400A-878E-220498F4EE31}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C1A3808-0F4F-43FB-A9FE-5F27A3BB2ECF}