src/DotNetCommon.Core/ICommonComponent.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Text;
namespace DotNetCommon
{
/// <summary>
/// 公共组件,方便将非泛型类注入到容器,使用示例:<br/>
/// <code>
/// // Startup.cs<br/>
/// services.AddScoped(provider => ComponentWraper.Create(new TestService()));
/// <br />
/// <br />
/// //TestController.cs
/// private readonly TestService testService;
/// public TestController(ComponentWraper<TestService> testService)
/// {
/// this.testService = testService.Value;
/// }
/// </code>
/// </summary>
/// <typeparam name="T"></typeparam>
public class ComponentWraper<T>
{
internal ComponentWraper() { }
/// <summary>
/// 组件
/// </summary>
public T Value { get; set; }
}
/// <summary>
/// 公共组件,方便将非泛型类注入到容器
/// </summary>
public static class ComponentWraper
{
/// <summary>
/// 创建实例
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static ComponentWraper<T> Create<T>(T value) => new ComponentWraper<T> { Value = value };
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
