Impossible to register multicast composite component because of recursion

Issue #18 resolved
Stefan Glienke repo owner created an issue

Following is not possible currently because it will raise ECircularDependencyException:

container.RegisterType<IObserver<TUnit>, TNeedyClass>('needy');
container.RegisterType<IObserver<TUnit>, TAnotherObserver>('another');
container.RegisterType<IObserver<TUnit>, TCompositeObserver<TUnit>>;

where TCompositeObserver<T> has this constructor:

constructor Create(const observers: TArray<IObserver<T>>);

Logically this should work because TCompositeObserver is a registration without name and thus will not be considered when resolving an array of IObserver<T>.

The workaround for now it to manually resolve the array like this:

container.RegisterType<IObserver<TUnit>, TNeedyClass>('needy');
container.RegisterType<IObserver<TUnit>, TAnotherObserver>('another');
container.RegisterType<IObserver<TUnit>, TCompositeObserver<TUnit>>.DelegateTo(
  function: TCompositeObserver<TUnit>
  begin
    Result := TCompositeObserver<TUnit>.Create(container.ResolveAll<IObserver<TUnit>>);
  end);

Comments (6)

  1. Log in to comment