Inversion of Control with .net

前端 未结 7 650
遥遥无期
遥遥无期 2021-01-01 00:51

It\'s rare that I hear someone using Inversion of Control (Ioc) principle with .Net. I have some friends that work with Java that use a lot more Ioc with Spring and PicoCont

7条回答
  •  误落风尘
    2021-01-01 01:46

    Lots of people use IOC in .NET, and there are several frameworks available to assist with using IoC. You may see it less in the WinForms side of things, because it's harder to just let the container wire everything together when you are designing forms in Visual Studio, but I can say that for server-side .NET applications, where I work at least, IoC is used very successfully.

    Why use it in .NET? For the same reason you use it everywhere else. The 2 biggest things I like are:

    • Designing for IoC tends to enforce good coding practice - designing to interfaces, low coupling, high cohesion. This also leads to classes that are very easy to unit-test.
    • System configuration can often be changed without recompiling.

    Some other posts discussing the different IoC/DI frameworks available for .NET:

    • Which C#/.net Dependency Injection frameworks are worth looking into?
    • Which Dependency Injection Tool Should I Use?

提交回复
热议问题