Inversion of control / dependency injection with good explanation and examples in .net?

Hi

I have little knowledge of the IoC / DI frameworks in the .NET Framework. Can someone give me links that explain IoC / DI in detail with a few examples in C #? I want to go through this and get more information about these structures.

So that I can get knowledge of where and how I can use these frameworks, it is useful in the implementation of the project.



NRK

+5
source share
4 answers
+12

Aim Kai IOC , IOC /.

.

+1

.

, foo, bar

public class Foo
{
      public Foo(Bar bar)
      {
      }
}

bar . , Bar, ?

, IBar , .

, , , , , , IBar, .

Instead, we can use dependency injection like this.

IUnityContainer myContainer = new UnityContainer();
myContainer.RegisterType<IBar, Bar>();
Foo foo = myContainer.Resolve<Foo>();

Here, the unity frame inserted the Bar object into the Foo constructor, if you change the type registration in one place, you will change how Foo objects are resolved everywhere.

When you have complex dependencies that can change, DI is needed!

0
source

All Articles