CodeM.Common.Ioc 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CodeM.Common.Ioc --version 1.0.2
NuGet\Install-Package CodeM.Common.Ioc -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeM.Common.Ioc" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CodeM.Common.Ioc --version 1.0.2
#r "nuget: CodeM.Common.Ioc, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CodeM.Common.Ioc as a Cake Addin
#addin nuget:?package=CodeM.Common.Ioc&version=1.0.2

// Install CodeM.Common.Ioc as a Cake Tool
#tool nuget:?package=CodeM.Common.Ioc&version=1.0.2

.netcore 轻量级IOC容器


Install

依赖安装

Package Manager
Install-Package CodeM.Common.Ioc -Version 1.0.1
.NET CLI
dotnet add package CodeM.Common.Ioc --version 1.0.1
PackageReference
<PackageReference Include="CodeM.Common.Ioc" Version="1.0.1" />
Paket CLI
paket add CodeM.Common.Ioc --version 1.0.1

API

一、添加程序集搜索路径(默认只在应用执行目录中搜索)

定义:

public static void AddSearchPath(string path)

参数:

path: 搜索路径,绝对路径。

返回:

二、移除程序集搜索路径

定义:

public static void RemoveSearchPath(string path)

参数:

path:搜索路径

返回:

三、加载对象配置文件

定义:

public static void LoadConfig(string configFile, bool append = true)

参数:

configFile: 配置文件,绝对路径。 <br> append: 是否使用添加模式,默认为true

返回:

四、根据类全名称获取对象实例

定义:

public static object GetObject(string classFullName, params object[] args)

参数:

classFullName: 类全名称。 <br> args: 对象构造参数数组。

返回:

对象实例。

五、根据类全名称获取指定类型的对象实例

定义:

public static T GetObject<T>(string classFullName, params object[] args)

参数:

classFullName: 类全名称。 <br> args: 对象构造参数数组。

返回:

指定类型的对象实例。

六、以单例模式根据类全名称获取对象实例

定义:

public static object GetSingleObject(string classFullName, params object[] args)

参数:

classFullName: 类全名称。 <br> args: 对象构造参数数组。

返回:

对象实例,多次调用返回同一实例。

七、以单例模式根据类全名称获取指定类型的对象实例

定义:

public static T GetSingleObject<T>(string classFullName, params object[] args)

参数:

classFullName: 类全名称。 <br> 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 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.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.1.1 1,378 6/4/2022
1.1.0 2,900 11/14/2021
1.0.8 421 11/3/2021
1.0.6 1,706 3/18/2021
1.0.5 660 3/3/2021
1.0.4 594 2/23/2021
1.0.3 373 2/10/2021
1.0.2 1,294 11/18/2020
1.0.1 609 6/11/2019
1.0.0 613 5/6/2019