项目 - 嵌入式IoC容器嵌入式、容器、项目、IoC

2023-09-04 09:05:14 作者:时尚时尚最时尚?

我要寻找一个非常简单和轻巧的IoC容器的的C#源代码可以被包含在我自己的项目的(因此不能使外部参考)。

I am looking for a really simple and lightweight IoC Container whose C# source can be included in my own project (thus not making an external reference).

这样做的原因是,我写的基础设施,并愿意提供一个.dll文件,无需任何额外的依赖。

The reason for this is that I am writing an infrastructure and would like to provide a single .dll file, without any additional dependencies.

我也不想ILMerge我的组装与IOC大会。

I also do not want to ILMerge my assembly with the IoC assembly..

我想到了MEF,其他一些建议吗?

I thought about MEF, some other suggestions?

推荐答案

如果您使用的是.NET 4.0,你有MEF包括在内。

If you're using .NET 4.0 you have MEF included.

对于.NET 2我曾经写过使用接口与思考类似的东西。有很多的教程在那里描述该过程。即使你可以使用MEF,它还是值得尝试的一些反思教程,因为这是MEF是如何工作的下面。

For .NET 2 I once wrote something similar using interfaces and Reflection. There are a lot of tutorials out there describing that process. Even if you can use MEF, its still worth attempting some reflection tutorials as this is how MEF works underneath.

另外,请查阅其中有一些很好的回答这个问题。 TinyIoC 看起来像它只是一个单一的源文件。

Also check out this question which has some good answers. TinyIoC looks like its just a single source file.