CodeM.Common.Ioc
1.0.0
See the version list below for details.
dotnet add package CodeM.Common.Ioc --version 1.0.0
NuGet\Install-Package CodeM.Common.Ioc -Version 1.0.0
<PackageReference Include="CodeM.Common.Ioc" Version="1.0.0" />
paket add CodeM.Common.Ioc --version 1.0.0
#r "nuget: CodeM.Common.Ioc, 1.0.0"
// Install CodeM.Common.Ioc as a Cake Addin #addin nuget:?package=CodeM.Common.Ioc&version=1.0.0 // Install CodeM.Common.Ioc as a Cake Tool #tool nuget:?package=CodeM.Common.Ioc&version=1.0.0
.netcore 轻量级IOC容器
一、添加程序集搜索路径(默认只在应用执行目录中搜索)
定义:
public static void AddSearchPath(string path)
参数:
path: 搜索路径,绝对路径。
返回:
无
二、移除程序集搜索路径
定义:
public static void RemoveSearchPath(string path)
参数:
path:搜索路径
返回:
无
三、加载对象配置文件
定义:
public static void LoadConfig(string configFile, bool append = true)
参数:
configFile: 配置文件,绝对路径。 append: 是否使用添加模式,默认为true
返回:
无
四、根据类全名称获取对象实例
定义:
public static object GetObject(string classFullName, params object[] args)
参数:
classFullName: 类全名称。 args: 对象构造参数数组。
返回:
对象实例。
五、根据类全名称获取指定类型的对象实例
定义:
public static T GetObject<T>(string classFullName, params object[] args)
参数:
classFullName: 类全名称。 args: 对象构造参数数组。
返回:
指定类型的对象实例。
六、以单例模式根据类全名称获取对象实例
定义:
public static object GetSingleObject(string classFullName, params object[] args)
参数:
classFullName: 类全名称。 args: 对象构造参数数组。
返回:
对象实例,多次调用返回同一实例。
七、以单例模式根据类全名称获取指定类型的对象实例
定义:
public static T GetSingleObject<T>(string classFullName, params object[] args)
参数:
classFullName: 类全名称。 args: 对象构造参数数组。
返回:
指定类型的对象实例,多次调用返回同一实例。
八、根据配置文件Id获取对象实例
定义:
public static object GetObjectById(string objectId)
参数:
objectId: 配置文件中对象Id
返回:
对象实例。
九、根据配置文件Id获取指定类型对象实例
定义:
public static T GetObjectById<T>(string objectId)
参数:
objectId: 配置文件中对象Id
返回:
指定类型的对象实例。
十、以单例模式根据配置文件Id获取对象实例
定义:
public static object GetSingleObjectById(string objectId)
参数:
objectId: 配置文件中对象Id
返回:
对象实例,多次调用返回同一实例。
十一、以单例模式根据配置文件Id获取指定类型的对象实例
定义:
public static T GetSingleObjectById<T>(string objectId)
参数:
objectId: 配置文件中对象Id
返回:
指定类型的对象实例,多次调用返回同一实例。
代码示例
object person = IocUtils.GetObject("TestLibrary.Person");
Console.WriteLine(person);
object person2 = IocUtils.GetObject("TestLibrary.Person", "张三");
Console.WriteLine(person2);
配置文件示例
<objects>
<object id="abc">
<constructor-arg>wangxm</constructor-arg>
<constructor-arg type="Int16">18</constructor-arg>
<constructor-arg type="TestLibrary.Sex">Male</constructor-arg>
<property name="name">王小明</property>
<property name="age">21</property>
</object>
</objects>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 is compatible. netcoreapp3.1 was computed. |
-
.NETCoreApp 3.0
- CodeM.Common.Tools (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CodeM.Common.Ioc:
Package | Downloads |
---|---|
CodeM.Common.Orm
一套轻量级Object/Relational Mapping通用数据库操作框架 |
GitHub repositories
This package is not used by any popular GitHub repositories.