Code your own IOC Container

前端 未结 12 858
眼角桃花
眼角桃花 2020-12-08 00:52

Has anyone out there written their own IOC Container in C#? Or do the vast majority of folks use the various frameworks such as Spring. What are the pro\'s and con\'s of eac

相关标签:
12条回答
  • 2020-12-08 01:15

    Unless there's a very good reason I wouldn't go reinvent the wheel and implement a IoC container myself, specially because there are are a lot of good options like Unity, Ninject or Spring.net.

    If you need/want to remove the dependency to any of these IoC containers you may try out the Common Service Locator interface.

    0 讨论(0)
  • 2020-12-08 01:18

    IOC container is not hard to write, it is just a well managed global recursive factory with some potential additional features. Using dictionary, reflection and delegate to register and build a simple container...

    The real question is why and how another new IOC container framework can bring benefits?

    In most of cases, you think you need more performance? non existing features? But most of time, existing frameworks is just what you need and enough, unless you have become aware of all the nonsense that the framework has forced you to do to use it.

    has the force of being disappointed by all the implementations of framework of ioc container of has features that are of the order of the antipattern, but also quirky and unreliable syntaxes and worse in ore of imposed couplings, I decided myself to experience it. This is why I made my own (very light) IOC container as open source.

    You can check it here : Puresharp API .net 4.5.2+

    0 讨论(0)
  • 2020-12-08 01:25

    I liked this 33 line container implementation from Ken Egozi inspired by Ayende's 15 liner

    0 讨论(0)
  • 2020-12-08 01:27

    If you are looking for lightweight & high performance IoC container, then you should check out Munq

    0 讨论(0)
  • 2020-12-08 01:27

    Ayende also wrote about writing your own IoC container in his blog post Building an IoC container in 15 lines of code, I believe he's of the same opinion as everyone else though: don't build your own if you don't have to.

    0 讨论(0)
  • 2020-12-08 01:31

    I have written an IoC / DI Container in c# that implements the Common Service Locator. I wrote it mostly for learning purposes, but when I completed it, I decided to make it open source. If any of you would like to try out IInject, it can downloaded here.

    0 讨论(0)
提交回复
热议问题