Enabling array types in a Unity container (Prism)

Is it possible to register and resolve array types in a Unity container? I would like to do something like this:

this.mContainer
    .RegisterType<ISomeType, SomeType>()
    .RegisterType<ISomeType[], SomeType[]>();
ISomeType[] lSomeTypes = this.mContainer.Resolve<ISomeType[6]>();

It would be even better if I did not have to register the type of the array, and Unity only calculates the array based on RegisterType<ISomeType, SomeType>()and Resolve<ISomeType[]>().

+5
source share
1 answer

If you register several types for a certain type (using named registrations), then when the container sees a dependency on an array of this type, it automatically enters all named registrations.

So this will work:

this.mContainer
  .RegisterType<ISomeType, SomeImpl1>("one")
  .RegisterType<ISomeType, SomeOtherImpl>("other")
  .RegisterType,ISomeType, AnotherImpl>("another");

ISomeType[] someTypes = mContainer.Resolve<ISomeType[]>();

, ISomeType [] - , ..

, . , .

+7

All Articles