You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicinterfaceIService<T>{}publicclassServiceA:IService<A>{publicServiceA(IValidator<A>validator){}}publicclassServiceB:IService<B>{publicServiceB(IValidator<B>validator){}}publicclassServiceC:IService<C>{publicServiceC(IService<C>validator){}// note the cyclic dependeny here.}publicclassCController{publicCController(IService<C>service){}}
container.Register(typeof(IService<>), typeof(IService<>).Assembly);
container.GetInstance<CController>();
Results in the following exception:
The registered delegate for type CController threw an exception. The constructor of type CController contains the parameter of type IService<C> with name 'service' that is not registered. Please ensure IService<C> is registered, or change the constructor of CController.
This exception is expected because Register searches for all non-generic IService<T> implementations, but skips any decorators that it encounters. ServiceC is a decorator, because it implements IService<C> and (probably) accidentally depends on IService<C> as well. This means that ServiceC is not registered and there is therefore no registration for IService<C> and this will therefore cause the "Please ensure IService is registered" message.
Although this behavior is correct and by design, it can be really confusing for the user that didn't notice his mistype in the constructor. A better exception in this case therefore might be:
The constructor of type CController contains the parameter of type IService<C> with name 'service' that is not registered. Please ensure IService<C> is registered, or change the constructor of CController. Note that ServiceC was found as implementation of IService<C>, but it was skipped by the container because it contains a cyclic reference to itself.
The text was updated successfully, but these errors were encountered:
The following code:
Results in the following exception:
This exception is expected because Register searches for all non-generic
IService<T>
implementations, but skips any decorators that it encounters.ServiceC
is a decorator, because it implementsIService<C>
and (probably) accidentally depends onIService<C>
as well. This means thatServiceC
is not registered and there is therefore no registration forIService<C>
and this will therefore cause the "Please ensure IService is registered" message.Although this behavior is correct and by design, it can be really confusing for the user that didn't notice his mistype in the constructor. A better exception in this case therefore might be:
The text was updated successfully, but these errors were encountered: