提交 2a4697b0 编写于 作者: 若汝棋茗's avatar 若汝棋茗

优化ConsoleAction

上级 bb83567a
......@@ -111,6 +111,17 @@ namespace RRQMCore.Dependency
this.Type = type;
}
/// <summary>
/// 类型,参数,属性指定性注入。
/// </summary>
/// <param name="type"></param>
/// <param name="ps"></param>
public DependencyParamterInjectAttribute(Type type, params object[] ps) : base(ps)
{
Key = string.Empty;
this.Type = type;
}
/// <summary>
/// 注入类型
/// </summary>
......
......@@ -13,6 +13,7 @@
using RRQMCore.Extensions;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
......@@ -25,7 +26,7 @@ namespace RRQMCore.Dependency
/// </summary>
public class Container : IContainer
{
private readonly Dictionary<string, DependencyDescriptor> registrations = new Dictionary<string, DependencyDescriptor>();
private readonly ConcurrentDictionary<string, DependencyDescriptor> registrations = new ConcurrentDictionary<string, DependencyDescriptor>();
/// <summary>
/// <inheritdoc/>
......@@ -35,7 +36,7 @@ namespace RRQMCore.Dependency
public void Register(DependencyDescriptor descriptor, string key = "")
{
string k = $"{descriptor.FromType.FullName}{key}";
registrations.AddOrUpdate(k, descriptor);
registrations.AddOrUpdate(k, descriptor,(k,v)=> { return v; });
}
private IScopedContainer GetScopedContainer()
......@@ -45,11 +46,11 @@ namespace RRQMCore.Dependency
{
if (item.Value.Lifetime == Lifetime.Scoped)
{
container.registrations.AddOrUpdate(item.Key, new DependencyDescriptor(item.Value.FromType, item.Value.ToType, Lifetime.Singleton));
container.registrations.AddOrUpdate(item.Key, new DependencyDescriptor(item.Value.FromType, item.Value.ToType, Lifetime.Singleton), (k, v) => { return v; });
}
else
{
container.registrations.AddOrUpdate(item.Key, item.Value);
container.registrations.AddOrUpdate(item.Key, item.Value, (k, v) => { return v; });
}
}
......@@ -149,11 +150,11 @@ namespace RRQMCore.Dependency
if (ctor is null)
{
//如果没有被特性标记,那就取构造函数参数最多的作为注入目标
ctor = toType.GetConstructors().OrderByDescending(x => x.GetParameters().Length).First();
if (ctor is null)
if (toType.GetConstructors().Length==0)
{
throw new RRQMException($"没有找到类型{toType.FullName}的公共构造函数。");
}
ctor = toType.GetConstructors().OrderByDescending(x => x.GetParameters().Length).First();
}
else
{
......
......@@ -12,6 +12,7 @@
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
namespace RRQMCore.IO
{
......@@ -53,13 +54,20 @@ namespace RRQMCore.IO
/// </summary>
public void ShowAll()
{
int max = this.actions.Values.Max(a=>a.FullOrder.Length)+8;
List<string> s = new List<string>();
foreach (var item in this.actions)
{
if (!s.Contains(item.Value.FullOrder.ToLower()))
{
s.Add(item.Value.FullOrder.ToLower());
Console.WriteLine($"[{item.Value.FullOrder}]-------->{item.Value.Description}");
Console.Write($"[{item.Value.FullOrder}]");
for (int i = 0; i < max- item.Value.FullOrder.Length; i++)
{
Console.Write("-");
}
Console.WriteLine(item.Value.Description);
}
}
}
......
......@@ -5,7 +5,7 @@
<Authors>若汝棋茗</Authors>
<PackageIcon>RRQM.png</PackageIcon>
<Copyright>Copyright © 2022 若汝棋茗</Copyright>
<Version>8.2.1</Version>
<Version>8.2.2</Version>
<LangVersion>8.0</LangVersion>
<SignAssembly>true</SignAssembly>
<Description>此程序集是RRQM的核心开源库,其中包含了内存池、高性能序列化、日志接口在内的很多基本内容。
......
......@@ -4,7 +4,7 @@
<ApplicationIcon>RRQM.ico</ApplicationIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>RRQM.pfx</AssemblyOriginatorKeyFile>
<Version>8.2.1</Version>
<Version>8.2.2</Version>
<LangVersion>8.0</LangVersion>
<Company>若汝棋茗</Company>
<Copyright>Copyright © 2022 若汝棋茗</Copyright>
......@@ -78,7 +78,7 @@ API:https://www.yuque.com/eo2w71/rrqm</Description>
</ItemGroup>
<ItemGroup>
<PackageReference Include="RRQMCore" Version="8.2.1" />
<PackageReference Include="RRQMCore" Version="8.2.2" />
</ItemGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册