What is an IOC container that is really here for me?

So, I completely redesigned the construct to install the constructor, and now I have a bootstrapper class that looks something like this:

var container = new UnityContainer();
container.RegisterType<Type1, Impl1>();
container.RegisterType<Type2, Impl2>();
container.RegisterType<Type3, Impl3>();
container.RegisterType<Type4, Impl4>();

var type4Impl = container.Resolve((typeof)Type4) as Type4;
type4Impl.Run();

I looked at him for a second before realizing that Unity really did nothing special for me. Left in ctor sigs, the above can be written as:

Type1 type1Impl = Impl1();
Type2 type2Impl = Impl2();
Type3 type3Impl = Impl3(type1Impl, type2Impl);
Type4 type4Impl = Impl4(type1Impl, type3Impl);
type4Impl.Run();

. , Unity . , (.. , , XML, ), , , , DI . ? , ?

+5
7

. .

. , IoC . Unity , .

+1

, DI , , . .

, , , Locator.

+6

- . IoC. - , .

IoC . IoC, , , .. ..

. . IoC , . , .

+3

, Unity, . , , . , Impl1 , Type1.

+1

, ( , , ..).

public interface IFoo { }
public interface IBar { IFoo FooImpl { get; set; } }
public interface IBaz { IBar BarImpl { get; set; } }
public interface IBat { IBaz BazImpl { get; set; } }

:

var bat = new Bat{
        BazImpl = new BazImpl() {
                    BarImpl = new BarImpl() {
                        FooImpl = new FooImpl()
                        }
                    }
                };

, , , :

var bat = container.Resolve<IBat>()
+1

, , , IoC. . , , , .

, IoC:

  • . Autofac ( Unity) , Func<IMyDependency> , IDependency, factory. -, DI, , , .
  • . , A B, B - C, A C. , Z, A, C. , IoC; A, B C , B, A factory, () A B, .
  • "singletoning". , , IoC , . , .
+1

, DI. , , DI .

DI , .

0

All Articles