Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
若汝棋茗
RRQMSocket
提交
0f41e2ba
RRQMSocket
项目概览
若汝棋茗
/
RRQMSocket
11 个月 前同步成功
通知
20
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
RRQMSocket
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0f41e2ba
编写于
9月 23, 2022
作者:
若
若汝棋茗
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复容器
上级
056e06e0
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
65 addition
and
28 deletion
+65
-28
src/TouchSocket.AspNetCore/Core/Common/AspNetCoreContainer.cs
...TouchSocket.AspNetCore/Core/Common/AspNetCoreContainer.cs
+62
-10
src/TouchSocket.AspNetCore/Rpc/TouchRpc/Components/WSTouchRpcClient.cs
...et.AspNetCore/Rpc/TouchRpc/Components/WSTouchRpcClient.cs
+1
-1
src/TouchSocket.AspNetCore/TouchSocket.AspNetCore.csproj
src/TouchSocket.AspNetCore/TouchSocket.AspNetCore.csproj
+2
-10
src/TouchSocket/TouchSocket.csproj
src/TouchSocket/TouchSocket.csproj
+0
-7
未找到文件。
src/TouchSocket.AspNetCore/Core/Common/AspNetCoreContainer.cs
浏览文件 @
0f41e2ba
...
...
@@ -12,6 +12,9 @@
//------------------------------------------------------------------------------
using
Microsoft.Extensions.DependencyInjection
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
TouchSocket.Core.Dependency
;
namespace
TouchSocket.Core.AspNetCore
...
...
@@ -22,7 +25,6 @@ namespace TouchSocket.Core.AspNetCore
public
class
AspNetCoreContainer
:
IContainer
{
private
readonly
IServiceCollection
m_services
;
private
readonly
Container
m_container
=
new
Container
();
/// <summary>
/// 初始化一个IServiceCollection的容器。
...
...
@@ -30,9 +32,24 @@ namespace TouchSocket.Core.AspNetCore
/// <param name="services"></param>
public
AspNetCoreContainer
(
IServiceCollection
services
)
{
services
.
AddSingleton
<
IContainer
>(
this
);
this
.
m_services
=
services
;
}
/// <summary>
/// 返回迭代器
/// </summary>
/// <returns></returns>
public
IEnumerator
<
DependencyDescriptor
>
GetEnumerator
()
{
return
this
.
m_services
.
ToList
().
Select
(
s
=>
{
DependencyDescriptor
descriptor
=
new
DependencyDescriptor
(
s
.
ServiceType
,
s
.
ImplementationType
,
(
Lifetime
)((
int
)
s
.
Lifetime
));
descriptor
.
ToInstance
=
s
.
ImplementationInstance
;
return
descriptor
;
}).
GetEnumerator
();
}
/// <summary>
/// <inheritdoc/>
/// </summary>
...
...
@@ -41,7 +58,19 @@ namespace TouchSocket.Core.AspNetCore
/// <returns></returns>
public
bool
IsRegistered
(
Type
fromType
,
string
key
=
""
)
{
return
((
IContainerProvider
)
this
.
m_container
).
IsRegistered
(
fromType
,
key
);
if
(
fromType
.
IsGenericType
)
{
fromType
=
fromType
.
GetGenericTypeDefinition
();
}
var
array
=
m_services
.
ToArray
();
foreach
(
var
item
in
array
)
{
if
(
item
.
ServiceType
==
fromType
)
{
return
true
;
}
}
return
false
;
}
/// <summary>
...
...
@@ -51,7 +80,14 @@ namespace TouchSocket.Core.AspNetCore
/// <param name="key"></param>
public
void
Register
(
DependencyDescriptor
descriptor
,
string
key
=
""
)
{
this
.
m_container
.
Register
(
descriptor
,
key
);
if
(!
key
.
IsNullOrEmpty
())
{
throw
new
NotSupportedException
(
$"
{
this
.
GetType
().
Name
}
不支持包含Key的多实现注入"
);
}
if
(
this
.
IsRegistered
(
descriptor
.
FromType
))
{
this
.
Unregister
(
descriptor
.
FromType
);
}
switch
(
descriptor
.
Lifetime
)
{
case
Lifetime
.
Singleton
:
...
...
@@ -64,6 +100,7 @@ namespace TouchSocket.Core.AspNetCore
this
.
m_services
.
AddSingleton
(
descriptor
.
FromType
,
descriptor
.
ToType
);
}
break
;
case
Lifetime
.
Transient
:
default
:
this
.
m_services
.
AddTransient
(
descriptor
.
FromType
,
descriptor
.
ToType
);
...
...
@@ -80,15 +117,17 @@ namespace TouchSocket.Core.AspNetCore
/// <returns></returns>
public
object
Resolve
(
Type
fromType
,
object
[]
ps
=
null
,
string
key
=
""
)
{
ServiceProvider
provider
=
this
.
m_services
.
BuildServiceProvider
();
object
obj
=
provider
.
GetService
(
fromType
);
if
(
obj
!=
null
)
if
(
fromType
==
typeof
(
IContainer
))
{
return
this
;
}
if
(
fromType
==
typeof
(
IServiceProvider
))
{
return
obj
;
return
this
.
m_services
.
BuildServiceProvider
()
;
}
ServiceProvider
provider
=
this
.
m_services
.
BuildServiceProvider
();
return
this
.
m_container
.
Resolve
(
fromType
,
ps
,
key
);
return
provider
.
GetService
(
fromType
);
}
/// <summary>
...
...
@@ -98,7 +137,20 @@ namespace TouchSocket.Core.AspNetCore
/// <param name="key"></param>
public
void
Unregister
(
DependencyDescriptor
descriptor
,
string
key
=
""
)
{
((
IContainer
)
this
.
m_container
).
Unregister
(
descriptor
,
key
);
var
array
=
m_services
.
ToArray
();
foreach
(
var
item
in
array
)
{
if
(
item
.
ServiceType
==
descriptor
.
FromType
)
{
m_services
.
Remove
(
item
);
return
;
}
}
}
IEnumerator
IEnumerable
.
GetEnumerator
()
{
return
this
.
GetEnumerator
();
}
}
}
\ No newline at end of file
src/TouchSocket.AspNetCore/Rpc/TouchRpc/Components/WSTouchRpcClient.cs
浏览文件 @
0f41e2ba
...
...
@@ -69,7 +69,7 @@ namespace TouchSocket.Rpc.TouchRpc.AspNetCore
/// <summary>
/// 断开连接
/// </summary>
public
event
ClientDisconnectedEventHandler
<
WSTouchRpcClient
>
Disconnected
;
public
ClientDisconnectedEventHandler
<
WSTouchRpcClient
>
Disconnected
{
get
;
set
;
}
/// <summary>
/// 方法映射表
...
...
src/TouchSocket.AspNetCore/TouchSocket.AspNetCore.csproj
浏览文件 @
0f41e2ba
...
...
@@ -5,7 +5,7 @@
<ApplicationIcon>logo.ico</ApplicationIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>RRQM.pfx</AssemblyOriginatorKeyFile>
<Version>0.7.
0
</Version>
<Version>0.7.
1
</Version>
<LangVersion>8.0</LangVersion>
<Company>若汝棋茗</Company>
<Copyright>Copyright © 2022 若汝棋茗</Copyright>
...
...
@@ -29,14 +29,6 @@ API:https://www.yuque.com/rrqm/touchsocket/index</Description>
<DebugSymbols>true</DebugSymbols>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<Deterministic>true</Deterministic>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6|AnyCPU'">
<DocumentationFile>bin\Debug\net6\TouchSocket.AspNetCore.xml</DocumentationFile>
...
...
@@ -77,6 +69,6 @@ API:https://www.yuque.com/rrqm/touchsocket/index</Description>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.26" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.0.0" />
<PackageReference Include="TouchSocket" Version="0.7.
0
" />
<PackageReference Include="TouchSocket" Version="0.7.
1
" />
</ItemGroup>
</Project>
src/TouchSocket/TouchSocket.csproj
浏览文件 @
0f41e2ba
...
...
@@ -27,16 +27,9 @@ API:https://www.yuque.com/rrqm/touchsocket/index
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<RepositoryUrl>https://gitee.com/dotnetchina/touchsocket</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<EmbedUntrackedSource>true</EmbedUntrackedSource>
<EmbedAllSources>true</EmbedAllSources>
<RepositoryType>Gitee</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<DocumentationFile>bin\Debug\netstandard2.0\TouchSocket.xml</DocumentationFile>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录